home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / perl / 5.10.0 / ExtUtils / MM_Unix.pm < prev    next >
Encoding:
Perl POD Document  |  2009-06-26  |  94.1 KB  |  3,710 lines

  1. package ExtUtils::MM_Unix;
  2.  
  3. require 5.005_03;  # Maybe further back, dunno
  4.  
  5. use strict;
  6.  
  7. use Carp;
  8. use ExtUtils::MakeMaker::Config;
  9. use File::Basename qw(basename dirname);
  10. use DirHandle;
  11.  
  12. use vars qw($VERSION @ISA
  13.             $Is_OS2 $Is_VMS $Is_Win32 $Is_Dos
  14.             $Is_OSF $Is_IRIX  $Is_NetBSD $Is_BSD
  15.             $Is_SunOS4 $Is_Solaris $Is_SunOS $Is_Interix
  16.             %Config_Override
  17.            );
  18.  
  19. use ExtUtils::MakeMaker qw($Verbose neatvalue);
  20.  
  21. $VERSION = '6.42';
  22.  
  23. require ExtUtils::MM_Any;
  24. @ISA = qw(ExtUtils::MM_Any);
  25.  
  26. BEGIN { 
  27.     $Is_OS2     = $^O eq 'os2';
  28.     $Is_Win32   = $^O eq 'MSWin32' || $Config{osname} eq 'NetWare';
  29.     $Is_Dos     = $^O eq 'dos';
  30.     $Is_VMS     = $^O eq 'VMS';
  31.     $Is_OSF     = $^O eq 'dec_osf';
  32.     $Is_IRIX    = $^O eq 'irix';
  33.     $Is_NetBSD  = $^O eq 'netbsd';
  34.     $Is_Interix = $^O eq 'interix';
  35.     $Is_SunOS4  = $^O eq 'sunos';
  36.     $Is_Solaris = $^O eq 'solaris';
  37.     $Is_SunOS   = $Is_SunOS4 || $Is_Solaris;
  38.     $Is_BSD     = ($^O =~ /^(?:free|net|open)bsd$/ or
  39.                    grep( $^O eq $_, qw(bsdos interix dragonfly) )
  40.                   );
  41. }
  42.  
  43. BEGIN {
  44.     if( $Is_VMS ) {
  45.         # For things like vmsify()
  46.         require VMS::Filespec;
  47.         VMS::Filespec->import;
  48.     }
  49. }
  50.  
  51.  
  52. =head1 NAME
  53.  
  54. ExtUtils::MM_Unix - methods used by ExtUtils::MakeMaker
  55.  
  56. =head1 SYNOPSIS
  57.  
  58. C<require ExtUtils::MM_Unix;>
  59.  
  60. =head1 DESCRIPTION
  61.  
  62. The methods provided by this package are designed to be used in
  63. conjunction with ExtUtils::MakeMaker. When MakeMaker writes a
  64. Makefile, it creates one or more objects that inherit their methods
  65. from a package C<MM>. MM itself doesn't provide any methods, but it
  66. ISA ExtUtils::MM_Unix class. The inheritance tree of MM lets operating
  67. specific packages take the responsibility for all the methods provided
  68. by MM_Unix. We are trying to reduce the number of the necessary
  69. overrides by defining rather primitive operations within
  70. ExtUtils::MM_Unix.
  71.  
  72. If you are going to write a platform specific MM package, please try
  73. to limit the necessary overrides to primitive methods, and if it is not
  74. possible to do so, let's work out how to achieve that gain.
  75.  
  76. If you are overriding any of these methods in your Makefile.PL (in the
  77. MY class), please report that to the makemaker mailing list. We are
  78. trying to minimize the necessary method overrides and switch to data
  79. driven Makefile.PLs wherever possible. In the long run less methods
  80. will be overridable via the MY class.
  81.  
  82. =head1 METHODS
  83.  
  84. The following description of methods is still under
  85. development. Please refer to the code for not suitably documented
  86. sections and complain loudly to the makemaker@perl.org mailing list.
  87. Better yet, provide a patch.
  88.  
  89. Not all of the methods below are overridable in a
  90. Makefile.PL. Overridable methods are marked as (o). All methods are
  91. overridable by a platform specific MM_*.pm file.
  92.  
  93. Cross-platform methods are being moved into MM_Any.  If you can't find
  94. something that used to be in here, look in MM_Any.
  95.  
  96. =cut
  97.  
  98. # So we don't have to keep calling the methods over and over again,
  99. # we have these globals to cache the values.  Faster and shrtr.
  100. my $Curdir  = __PACKAGE__->curdir;
  101. my $Rootdir = __PACKAGE__->rootdir;
  102. my $Updir   = __PACKAGE__->updir;
  103.  
  104.  
  105. =head2 Methods
  106.  
  107. =over 4
  108.  
  109. =item os_flavor
  110.  
  111. Simply says that we're Unix.
  112.  
  113. =cut
  114.  
  115. sub os_flavor {
  116.     return('Unix');
  117. }
  118.  
  119.  
  120. =item c_o (o)
  121.  
  122. Defines the suffix rules to compile different flavors of C files to
  123. object files.
  124.  
  125. =cut
  126.  
  127. sub c_o {
  128. # --- Translation Sections ---
  129.  
  130.     my($self) = shift;
  131.     return '' unless $self->needs_linking();
  132.     my(@m);
  133.     
  134.     my $command = '$(CCCMD)';
  135.     my $flags   = '$(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE)';
  136.     
  137.     if (my $cpp = $Config{cpprun}) {
  138.         my $cpp_cmd = $self->const_cccmd;
  139.         $cpp_cmd =~ s/^CCCMD\s*=\s*\$\(CC\)/$cpp/;
  140.         push @m, qq{
  141. .c.i:
  142.     $cpp_cmd $flags \$*.c > \$*.i
  143. };
  144.     }
  145.  
  146.     push @m, qq{
  147. .c.s:
  148.     $command -S $flags \$*.c
  149.  
  150. .c\$(OBJ_EXT):
  151.     $command $flags \$*.c
  152.  
  153. .cpp\$(OBJ_EXT):
  154.     $command $flags \$*.cpp
  155.  
  156. .cxx\$(OBJ_EXT):
  157.     $command $flags \$*.cxx
  158.  
  159. .cc\$(OBJ_EXT):
  160.     $command $flags \$*.cc
  161. };
  162.  
  163.     push @m, qq{
  164. .C\$(OBJ_EXT):
  165.     $command \$*.C
  166. } if !$Is_OS2 and !$Is_Win32 and !$Is_Dos; #Case-specific
  167.  
  168.     return join "", @m;
  169. }
  170.  
  171. =item cflags (o)
  172.  
  173. Does very much the same as the cflags script in the perl
  174. distribution. It doesn't return the whole compiler command line, but
  175. initializes all of its parts. The const_cccmd method then actually
  176. returns the definition of the CCCMD macro which uses these parts.
  177.  
  178. =cut
  179.  
  180. #'
  181.  
  182. sub cflags {
  183.     my($self,$libperl)=@_;
  184.     return $self->{CFLAGS} if $self->{CFLAGS};
  185.     return '' unless $self->needs_linking();
  186.  
  187.     my($prog, $uc, $perltype, %cflags);
  188.     $libperl ||= $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ;
  189.     $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/;
  190.  
  191.     @cflags{qw(cc ccflags optimize shellflags)}
  192.     = @Config{qw(cc ccflags optimize shellflags)};
  193.     my($optdebug) = "";
  194.  
  195.     $cflags{shellflags} ||= '';
  196.  
  197.     my(%map) =  (
  198.         D =>   '-DDEBUGGING',
  199.         E =>   '-DEMBED',
  200.         DE =>  '-DDEBUGGING -DEMBED',
  201.         M =>   '-DEMBED -DMULTIPLICITY',
  202.         DM =>  '-DDEBUGGING -DEMBED -DMULTIPLICITY',
  203.         );
  204.  
  205.     if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){
  206.     $uc = uc($1);
  207.     } else {
  208.     $uc = ""; # avoid warning
  209.     }
  210.     $perltype = $map{$uc} ? $map{$uc} : "";
  211.  
  212.     if ($uc =~ /^D/) {
  213.     $optdebug = "-g";
  214.     }
  215.  
  216.  
  217.     my($name);
  218.     ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
  219.     if ($prog = $Config{$name}) {
  220.     # Expand hints for this extension via the shell
  221.     print STDOUT "Processing $name hint:\n" if $Verbose;
  222.     my(@o)=`cc=\"$cflags{cc}\"
  223.       ccflags=\"$cflags{ccflags}\"
  224.       optimize=\"$cflags{optimize}\"
  225.       perltype=\"$cflags{perltype}\"
  226.       optdebug=\"$cflags{optdebug}\"
  227.       eval '$prog'
  228.       echo cc=\$cc
  229.       echo ccflags=\$ccflags
  230.       echo optimize=\$optimize
  231.       echo perltype=\$perltype
  232.       echo optdebug=\$optdebug
  233.       `;
  234.     my($line);
  235.     foreach $line (@o){
  236.         chomp $line;
  237.         if ($line =~ /(.*?)=\s*(.*)\s*$/){
  238.         $cflags{$1} = $2;
  239.         print STDOUT "    $1 = $2\n" if $Verbose;
  240.         } else {
  241.         print STDOUT "Unrecognised result from hint: '$line'\n";
  242.         }
  243.     }
  244.     }
  245.  
  246.     if ($optdebug) {
  247.     $cflags{optimize} = $optdebug;
  248.     }
  249.  
  250.     for (qw(ccflags optimize perltype)) {
  251.         $cflags{$_} ||= '';
  252.     $cflags{$_} =~ s/^\s+//;
  253.     $cflags{$_} =~ s/\s+/ /g;
  254.     $cflags{$_} =~ s/\s+$//;
  255.     $self->{uc $_} ||= $cflags{$_};
  256.     }
  257.  
  258.     if ($self->{POLLUTE}) {
  259.     $self->{CCFLAGS} .= ' -DPERL_POLLUTE ';
  260.     }
  261.  
  262.     my $pollute = '';
  263.     if ($Config{usemymalloc} and not $Config{bincompat5005}
  264.     and not $Config{ccflags} =~ /-DPERL_POLLUTE_MALLOC\b/
  265.     and $self->{PERL_MALLOC_OK}) {
  266.     $pollute = '$(PERL_MALLOC_DEF)';
  267.     }
  268.  
  269.     $self->{CCFLAGS}  = quote_paren($self->{CCFLAGS});
  270.     $self->{OPTIMIZE} = quote_paren($self->{OPTIMIZE});
  271.  
  272.     return $self->{CFLAGS} = qq{
  273. CCFLAGS = $self->{CCFLAGS}
  274. OPTIMIZE = $self->{OPTIMIZE}
  275. PERLTYPE = $self->{PERLTYPE}
  276. MPOLLUTE = $pollute
  277. };
  278.  
  279. }
  280.  
  281.  
  282. =item const_cccmd (o)
  283.  
  284. Returns the full compiler call for C programs and stores the
  285. definition in CONST_CCCMD.
  286.  
  287. =cut
  288.  
  289. sub const_cccmd {
  290.     my($self,$libperl)=@_;
  291.     return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
  292.     return '' unless $self->needs_linking();
  293.     return $self->{CONST_CCCMD} =
  294.     q{CCCMD = $(CC) -c $(PASTHRU_INC) $(INC) \\
  295.     $(CCFLAGS) $(OPTIMIZE) \\
  296.     $(PERLTYPE) $(MPOLLUTE) $(DEFINE_VERSION) \\
  297.     $(XS_DEFINE_VERSION)};
  298. }
  299.  
  300. =item const_config (o)
  301.  
  302. Defines a couple of constants in the Makefile that are imported from
  303. %Config.
  304.  
  305. =cut
  306.  
  307. sub const_config {
  308. # --- Constants Sections ---
  309.  
  310.     my($self) = shift;
  311.     my(@m,$m);
  312.     push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
  313.     push(@m,"\n# They may have been overridden via Makefile.PL or on the command line\n");
  314.     my(%once_only);
  315.     foreach $m (@{$self->{CONFIG}}){
  316.     # SITE*EXP macros are defined in &constants; avoid duplicates here
  317.     next if $once_only{$m};
  318.     $self->{uc $m} = quote_paren($self->{uc $m});
  319.     push @m, uc($m) , ' = ' , $self->{uc $m}, "\n";
  320.     $once_only{$m} = 1;
  321.     }
  322.     join('', @m);
  323. }
  324.  
  325. =item const_loadlibs (o)
  326.  
  327. Defines EXTRALIBS, LDLOADLIBS, BSLOADLIBS, LD_RUN_PATH. See
  328. L<ExtUtils::Liblist> for details.
  329.  
  330. =cut
  331.  
  332. sub const_loadlibs {
  333.     my($self) = shift;
  334.     return "" unless $self->needs_linking;
  335.     my @m;
  336.     push @m, qq{
  337. # $self->{NAME} might depend on some other libraries:
  338. # See ExtUtils::Liblist for details
  339. #
  340. };
  341.     my($tmp);
  342.     for $tmp (qw/
  343.      EXTRALIBS LDLOADLIBS BSLOADLIBS
  344.      /) {
  345.     next unless defined $self->{$tmp};
  346.     push @m, "$tmp = $self->{$tmp}\n";
  347.     }
  348.     # don't set LD_RUN_PATH if empty
  349.     for $tmp (qw/
  350.      LD_RUN_PATH
  351.      /) {
  352.     next unless $self->{$tmp};
  353.     push @m, "$tmp = $self->{$tmp}\n";
  354.     }
  355.     return join "", @m;
  356. }
  357.  
  358. =item constants (o)
  359.  
  360.   my $make_frag = $mm->constants;
  361.  
  362. Prints out macros for lots of constants.
  363.  
  364. =cut
  365.  
  366. sub constants {
  367.     my($self) = @_;
  368.     my @m = ();
  369.  
  370.     $self->{DFSEP} = '$(DIRFILESEP)';  # alias for internal use
  371.  
  372.     for my $macro (qw(
  373.  
  374.               AR_STATIC_ARGS DIRFILESEP DFSEP
  375.               NAME NAME_SYM 
  376.               VERSION    VERSION_MACRO    VERSION_SYM DEFINE_VERSION
  377.               XS_VERSION XS_VERSION_MACRO             XS_DEFINE_VERSION
  378.               INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB
  379.               INST_MAN1DIR INST_MAN3DIR
  380.               MAN1EXT      MAN3EXT
  381.               INSTALLDIRS INSTALL_BASE DESTDIR PREFIX
  382.               PERLPREFIX      SITEPREFIX      VENDORPREFIX
  383.                    ),
  384.                    (map { ("INSTALL".$_,
  385.                           "DESTINSTALL".$_)
  386.                         } $self->installvars),
  387.                    qw(
  388.               PERL_LIB    
  389.               PERL_ARCHLIB
  390.               LIBPERL_A MYEXTLIB
  391.               FIRST_MAKEFILE MAKEFILE_OLD MAKE_APERL_FILE 
  392.               PERLMAINCC PERL_SRC PERL_INC 
  393.               PERL            FULLPERL          ABSPERL
  394.               PERLRUN         FULLPERLRUN       ABSPERLRUN
  395.               PERLRUNINST     FULLPERLRUNINST   ABSPERLRUNINST
  396.               PERL_CORE
  397.               PERM_RW PERM_RWX
  398.  
  399.           ) ) 
  400.     {
  401.     next unless defined $self->{$macro};
  402.  
  403.         # pathnames can have sharp signs in them; escape them so
  404.         # make doesn't think it is a comment-start character.
  405.         $self->{$macro} =~ s/#/\\#/g;
  406.     push @m, "$macro = $self->{$macro}\n";
  407.     }
  408.  
  409.     push @m, qq{
  410. MAKEMAKER   = $self->{MAKEMAKER}
  411. MM_VERSION  = $self->{MM_VERSION}
  412. MM_REVISION = $self->{MM_REVISION}
  413. };
  414.  
  415.     push @m, q{
  416. # FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
  417. # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
  418. # PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
  419. # DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
  420. };
  421.  
  422.     for my $macro (qw/
  423.               MAKE
  424.           FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
  425.           LDFROM LINKTYPE BOOTDEP
  426.           /    ) 
  427.     {
  428.     next unless defined $self->{$macro};
  429.     push @m, "$macro = $self->{$macro}\n";
  430.     }
  431.  
  432.     push @m, "
  433. # Handy lists of source code files:
  434. XS_FILES = ".$self->wraplist(sort keys %{$self->{XS}})."
  435. C_FILES  = ".$self->wraplist(@{$self->{C}})."
  436. O_FILES  = ".$self->wraplist(@{$self->{O_FILES}})."
  437. H_FILES  = ".$self->wraplist(@{$self->{H}})."
  438. MAN1PODS = ".$self->wraplist(sort keys %{$self->{MAN1PODS}})."
  439. MAN3PODS = ".$self->wraplist(sort keys %{$self->{MAN3PODS}})."
  440. ";
  441.  
  442.  
  443.     push @m, q{
  444. # Where is the Config information that we are using/depend on
  445. CONFIGDEP = $(PERL_ARCHLIB)$(DFSEP)Config.pm $(PERL_INC)$(DFSEP)config.h
  446. };
  447.  
  448.  
  449.     push @m, qq{
  450. # Where to build things
  451. INST_LIBDIR      = $self->{INST_LIBDIR}
  452. INST_ARCHLIBDIR  = $self->{INST_ARCHLIBDIR}
  453.  
  454. INST_AUTODIR     = $self->{INST_AUTODIR}
  455. INST_ARCHAUTODIR = $self->{INST_ARCHAUTODIR}
  456.  
  457. INST_STATIC      = $self->{INST_STATIC}
  458. INST_DYNAMIC     = $self->{INST_DYNAMIC}
  459. INST_BOOT        = $self->{INST_BOOT}
  460. };
  461.  
  462.  
  463.     push @m, qq{
  464. # Extra linker info
  465. EXPORT_LIST        = $self->{EXPORT_LIST}
  466. PERL_ARCHIVE       = $self->{PERL_ARCHIVE}
  467. PERL_ARCHIVE_AFTER = $self->{PERL_ARCHIVE_AFTER}
  468. };
  469.  
  470.     push @m, "
  471.  
  472. TO_INST_PM = ".$self->wraplist(sort keys %{$self->{PM}})."
  473.  
  474. PM_TO_BLIB = ".$self->wraplist(%{$self->{PM}})."
  475. ";
  476.  
  477.     join('',@m);
  478. }
  479.  
  480.  
  481. =item depend (o)
  482.  
  483. Same as macro for the depend attribute.
  484.  
  485. =cut
  486.  
  487. sub depend {
  488.     my($self,%attribs) = @_;
  489.     my(@m,$key,$val);
  490.     while (($key,$val) = each %attribs){
  491.     last unless defined $key;
  492.     push @m, "$key : $val\n";
  493.     }
  494.     join "", @m;
  495. }
  496.  
  497.  
  498. =item init_DEST
  499.  
  500.   $mm->init_DEST
  501.  
  502. Defines the DESTDIR and DEST* variables paralleling the INSTALL*.
  503.  
  504. =cut
  505.  
  506. sub init_DEST {
  507.     my $self = shift;
  508.  
  509.     # Initialize DESTDIR
  510.     $self->{DESTDIR} ||= '';
  511.  
  512.     # Make DEST variables.
  513.     foreach my $var ($self->installvars) {
  514.         my $destvar = 'DESTINSTALL'.$var;
  515.         $self->{$destvar} ||= '$(DESTDIR)$(INSTALL'.$var.')';
  516.     }
  517. }
  518.  
  519.  
  520. =item init_dist
  521.  
  522.   $mm->init_dist;
  523.  
  524. Defines a lot of macros for distribution support.
  525.  
  526.   macro         description                     default
  527.  
  528.   TAR           tar command to use              tar
  529.   TARFLAGS      flags to pass to TAR            cvf
  530.  
  531.   ZIP           zip command to use              zip
  532.   ZIPFLAGS      flags to pass to ZIP            -r
  533.  
  534.   COMPRESS      compression command to          gzip --best
  535.                 use for tarfiles
  536.   SUFFIX        suffix to put on                .gz 
  537.                 compressed files
  538.  
  539.   SHAR          shar command to use             shar
  540.  
  541.   PREOP         extra commands to run before
  542.                 making the archive 
  543.   POSTOP        extra commands to run after
  544.                 making the archive
  545.  
  546.   TO_UNIX       a command to convert linefeeds
  547.                 to Unix style in your archive 
  548.  
  549.   CI            command to checkin your         ci -u
  550.                 sources to version control
  551.   RCS_LABEL     command to label your sources   rcs -Nv$(VERSION_SYM): -q
  552.                 just after CI is run
  553.  
  554.   DIST_CP       $how argument to manicopy()     best
  555.                 when the distdir is created
  556.  
  557.   DIST_DEFAULT  default target to use to        tardist
  558.                 create a distribution
  559.  
  560.   DISTVNAME     name of the resulting archive   $(DISTNAME)-$(VERSION)
  561.                 (minus suffixes)
  562.  
  563. =cut
  564.  
  565. sub init_dist {
  566.     my $self = shift;
  567.  
  568.     $self->{TAR}      ||= 'tar';
  569.     $self->{TARFLAGS} ||= 'cvf';
  570.     $self->{ZIP}      ||= 'zip';
  571.     $self->{ZIPFLAGS} ||= '-r';
  572.     $self->{COMPRESS} ||= 'gzip --best';
  573.     $self->{SUFFIX}   ||= '.gz';
  574.     $self->{SHAR}     ||= 'shar';
  575.     $self->{PREOP}    ||= '$(NOECHO) $(NOOP)'; # eg update MANIFEST
  576.     $self->{POSTOP}   ||= '$(NOECHO) $(NOOP)'; # eg remove the distdir
  577.     $self->{TO_UNIX}  ||= '$(NOECHO) $(NOOP)';
  578.  
  579.     $self->{CI}       ||= 'ci -u';
  580.     $self->{RCS_LABEL}||= 'rcs -Nv$(VERSION_SYM): -q';
  581.     $self->{DIST_CP}  ||= 'best';
  582.     $self->{DIST_DEFAULT} ||= 'tardist';
  583.  
  584.     ($self->{DISTNAME} = $self->{NAME}) =~ s{::}{-}g unless $self->{DISTNAME};
  585.     $self->{DISTVNAME} ||= $self->{DISTNAME}.'-'.$self->{VERSION};
  586.  
  587. }
  588.  
  589. =item dist (o)
  590.  
  591.   my $dist_macros = $mm->dist(%overrides);
  592.  
  593. Generates a make fragment defining all the macros initialized in
  594. init_dist.
  595.  
  596. %overrides can be used to override any of the above.
  597.  
  598. =cut
  599.  
  600. sub dist {
  601.     my($self, %attribs) = @_;
  602.  
  603.     my $make = '';
  604.     foreach my $key (qw( 
  605.             TAR TARFLAGS ZIP ZIPFLAGS COMPRESS SUFFIX SHAR
  606.             PREOP POSTOP TO_UNIX
  607.             CI RCS_LABEL DIST_CP DIST_DEFAULT
  608.             DISTNAME DISTVNAME
  609.            ))
  610.     {
  611.         my $value = $attribs{$key} || $self->{$key};
  612.         $make .= "$key = $value\n";
  613.     }
  614.  
  615.     return $make;
  616. }
  617.  
  618. =item dist_basics (o)
  619.  
  620. Defines the targets distclean, distcheck, skipcheck, manifest, veryclean.
  621.  
  622. =cut
  623.  
  624. sub dist_basics {
  625.     my($self) = shift;
  626.  
  627.     return <<'MAKE_FRAG';
  628. distclean :: realclean distcheck
  629.     $(NOECHO) $(NOOP)
  630.  
  631. distcheck :
  632.     $(PERLRUN) "-MExtUtils::Manifest=fullcheck" -e fullcheck
  633.  
  634. skipcheck :
  635.     $(PERLRUN) "-MExtUtils::Manifest=skipcheck" -e skipcheck
  636.  
  637. manifest :
  638.     $(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest
  639.  
  640. veryclean : realclean
  641.     $(RM_F) *~ */*~ *.orig */*.orig *.bak */*.bak *.old */*.old 
  642.  
  643. MAKE_FRAG
  644.  
  645. }
  646.  
  647. =item dist_ci (o)
  648.  
  649. Defines a check in target for RCS.
  650.  
  651. =cut
  652.  
  653. sub dist_ci {
  654.     my($self) = shift;
  655.     return q{
  656. ci :
  657.     $(PERLRUN) "-MExtUtils::Manifest=maniread" \\
  658.       -e "@all = keys %{ maniread() };" \\
  659.       -e "print(qq{Executing $(CI) @all\n}); system(qq{$(CI) @all});" \\
  660.       -e "print(qq{Executing $(RCS_LABEL) ...\n}); system(qq{$(RCS_LABEL) @all});"
  661. };
  662. }
  663.  
  664. =item dist_core (o)
  665.  
  666.   my $dist_make_fragment = $MM->dist_core;
  667.  
  668. Puts the targets necessary for 'make dist' together into one make
  669. fragment.
  670.  
  671. =cut
  672.  
  673. sub dist_core {
  674.     my($self) = shift;
  675.  
  676.     my $make_frag = '';
  677.     foreach my $target (qw(dist tardist uutardist tarfile zipdist zipfile 
  678.                            shdist))
  679.     {
  680.         my $method = $target.'_target';
  681.         $make_frag .= "\n";
  682.         $make_frag .= $self->$method();
  683.     }
  684.  
  685.     return $make_frag;
  686. }
  687.  
  688.  
  689. =item B<dist_target>
  690.  
  691.   my $make_frag = $MM->dist_target;
  692.  
  693. Returns the 'dist' target to make an archive for distribution.  This
  694. target simply checks to make sure the Makefile is up-to-date and
  695. depends on $(DIST_DEFAULT).
  696.  
  697. =cut
  698.  
  699. sub dist_target {
  700.     my($self) = shift;
  701.  
  702.     my $date_check = $self->oneliner(<<'CODE', ['-l']);
  703. print 'Warning: Makefile possibly out of date with $(VERSION_FROM)'
  704.     if -e '$(VERSION_FROM)' and -M '$(VERSION_FROM)' < -M '$(FIRST_MAKEFILE)';
  705. CODE
  706.  
  707.     return sprintf <<'MAKE_FRAG', $date_check;
  708. dist : $(DIST_DEFAULT) $(FIRST_MAKEFILE)
  709.     $(NOECHO) %s
  710. MAKE_FRAG
  711. }
  712.  
  713. =item B<tardist_target>
  714.  
  715.   my $make_frag = $MM->tardist_target;
  716.  
  717. Returns the 'tardist' target which is simply so 'make tardist' works.
  718. The real work is done by the dynamically named tardistfile_target()
  719. method, tardist should have that as a dependency.
  720.  
  721. =cut
  722.  
  723. sub tardist_target {
  724.     my($self) = shift;
  725.  
  726.     return <<'MAKE_FRAG';
  727. tardist : $(DISTVNAME).tar$(SUFFIX)
  728.     $(NOECHO) $(NOOP)
  729. MAKE_FRAG
  730. }
  731.  
  732. =item B<zipdist_target>
  733.  
  734.   my $make_frag = $MM->zipdist_target;
  735.  
  736. Returns the 'zipdist' target which is simply so 'make zipdist' works.
  737. The real work is done by the dynamically named zipdistfile_target()
  738. method, zipdist should have that as a dependency.
  739.  
  740. =cut
  741.  
  742. sub zipdist_target {
  743.     my($self) = shift;
  744.  
  745.     return <<'MAKE_FRAG';
  746. zipdist : $(DISTVNAME).zip
  747.     $(NOECHO) $(NOOP)
  748. MAKE_FRAG
  749. }
  750.  
  751. =item B<tarfile_target>
  752.  
  753.   my $make_frag = $MM->tarfile_target;
  754.  
  755. The name of this target is the name of the tarball generated by
  756. tardist.  This target does the actual work of turning the distdir into
  757. a tarball.
  758.  
  759. =cut
  760.  
  761. sub tarfile_target {
  762.     my($self) = shift;
  763.  
  764.     return <<'MAKE_FRAG';
  765. $(DISTVNAME).tar$(SUFFIX) : distdir
  766.     $(PREOP)
  767.     $(TO_UNIX)
  768.     $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
  769.     $(RM_RF) $(DISTVNAME)
  770.     $(COMPRESS) $(DISTVNAME).tar
  771.     $(POSTOP)
  772. MAKE_FRAG
  773. }
  774.  
  775. =item zipfile_target
  776.  
  777.   my $make_frag = $MM->zipfile_target;
  778.  
  779. The name of this target is the name of the zip file generated by
  780. zipdist.  This target does the actual work of turning the distdir into
  781. a zip file.
  782.  
  783. =cut
  784.  
  785. sub zipfile_target {
  786.     my($self) = shift;
  787.  
  788.     return <<'MAKE_FRAG';
  789. $(DISTVNAME).zip : distdir
  790.     $(PREOP)
  791.     $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME)
  792.     $(RM_RF) $(DISTVNAME)
  793.     $(POSTOP)
  794. MAKE_FRAG
  795. }
  796.  
  797. =item uutardist_target
  798.  
  799.   my $make_frag = $MM->uutardist_target;
  800.  
  801. Converts the tarfile into a uuencoded file
  802.  
  803. =cut
  804.  
  805. sub uutardist_target {
  806.     my($self) = shift;
  807.  
  808.     return <<'MAKE_FRAG';
  809. uutardist : $(DISTVNAME).tar$(SUFFIX)
  810.     uuencode $(DISTVNAME).tar$(SUFFIX) $(DISTVNAME).tar$(SUFFIX) > $(DISTVNAME).tar$(SUFFIX)_uu
  811. MAKE_FRAG
  812. }
  813.  
  814.  
  815. =item shdist_target
  816.  
  817.   my $make_frag = $MM->shdist_target;
  818.  
  819. Converts the distdir into a shell archive.
  820.  
  821. =cut
  822.  
  823. sub shdist_target {
  824.     my($self) = shift;
  825.  
  826.     return <<'MAKE_FRAG';
  827. shdist : distdir
  828.     $(PREOP)
  829.     $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
  830.     $(RM_RF) $(DISTVNAME)
  831.     $(POSTOP)
  832. MAKE_FRAG
  833. }
  834.  
  835.  
  836. =item dlsyms (o)
  837.  
  838. Used by some OS' to define DL_FUNCS and DL_VARS and write the *.exp files.
  839.  
  840. Normally just returns an empty string.
  841.  
  842. =cut
  843.  
  844. sub dlsyms {
  845.     return '';
  846. }
  847.  
  848.  
  849. =item dynamic_bs (o)
  850.  
  851. Defines targets for bootstrap files.
  852.  
  853. =cut
  854.  
  855. sub dynamic_bs {
  856.     my($self, %attribs) = @_;
  857.     return '
  858. BOOTSTRAP =
  859. ' unless $self->has_link_code();
  860.  
  861.     my $target = $Is_VMS ? '$(MMS$TARGET)' : '$@';
  862.  
  863.     return sprintf <<'MAKE_FRAG', ($target) x 5;
  864. BOOTSTRAP = $(BASEEXT).bs
  865.  
  866. # As Mkbootstrap might not write a file (if none is required)
  867. # we use touch to prevent make continually trying to remake it.
  868. # The DynaLoader only reads a non-empty file.
  869. $(BOOTSTRAP) : $(FIRST_MAKEFILE) $(BOOTDEP) $(INST_ARCHAUTODIR)$(DFSEP).exists
  870.     $(NOECHO) $(ECHO) "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))"
  871.     $(NOECHO) $(PERLRUN) \
  872.         "-MExtUtils::Mkbootstrap" \
  873.         -e "Mkbootstrap('$(BASEEXT)','$(BSLOADLIBS)');"
  874.     $(NOECHO) $(TOUCH) %s
  875.     $(CHMOD) $(PERM_RW) %s
  876.  
  877. $(INST_BOOT) : $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists
  878.     $(NOECHO) $(RM_RF) %s
  879.     - $(CP) $(BOOTSTRAP) %s
  880.     $(CHMOD) $(PERM_RW) %s
  881. MAKE_FRAG
  882. }
  883.  
  884. =item dynamic_lib (o)
  885.  
  886. Defines how to produce the *.so (or equivalent) files.
  887.  
  888. =cut
  889.  
  890. sub dynamic_lib {
  891.     my($self, %attribs) = @_;
  892.     return '' unless $self->needs_linking(); #might be because of a subdir
  893.  
  894.     return '' unless $self->has_link_code;
  895.  
  896.     my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
  897.     my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
  898.     my($armaybe) = $attribs{ARMAYBE} || $self->{ARMAYBE} || ":";
  899.     my($ldfrom) = '$(LDFROM)';
  900.     $armaybe = 'ar' if ($Is_OSF and $armaybe eq ':');
  901.     my(@m);
  902.     my $ld_opt = $Is_OS2 ? '$(OPTIMIZE) ' : '';    # Useful on other systems too?
  903.     my $ld_fix = $Is_OS2 ? '|| ( $(RM_F) $@ && sh -c false )' : '';
  904.     push(@m,'
  905. # This section creates the dynamically loadable $(INST_DYNAMIC)
  906. # from $(OBJECT) and possibly $(MYEXTLIB).
  907. ARMAYBE = '.$armaybe.'
  908. OTHERLDFLAGS = '.$ld_opt.$otherldflags.'
  909. INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
  910. INST_DYNAMIC_FIX = '.$ld_fix.'
  911.  
  912. $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP)
  913. ');
  914.     if ($armaybe ne ':'){
  915.     $ldfrom = 'tmp$(LIB_EXT)';
  916.     push(@m,'    $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
  917.     push(@m,'    $(RANLIB) '."$ldfrom\n");
  918.     }
  919.     $ldfrom = "-all $ldfrom -none" if $Is_OSF;
  920.  
  921.     # The IRIX linker doesn't use LD_RUN_PATH
  922.     my $ldrun = $Is_IRIX && $self->{LD_RUN_PATH} ?         
  923.                        qq{-rpath "$self->{LD_RUN_PATH}"} : '';
  924.  
  925.     # For example in AIX the shared objects/libraries from previous builds
  926.     # linger quite a while in the shared dynalinker cache even when nobody
  927.     # is using them.  This is painful if one for instance tries to restart
  928.     # a failed build because the link command will fail unnecessarily 'cos
  929.     # the shared object/library is 'busy'.
  930.     push(@m,'    $(RM_F) $@
  931. ');
  932.  
  933.     my $libs = '$(LDLOADLIBS)';
  934.  
  935.     if (($Is_NetBSD || $Is_Interix) && $Config{'useshrplib'} eq 'true') {
  936.     # Use nothing on static perl platforms, and to the flags needed
  937.     # to link against the shared libperl library on shared perl
  938.     # platforms.  We peek at lddlflags to see if we need -Wl,-R
  939.     # or -R to add paths to the run-time library search path.
  940.         if ($Config{'lddlflags'} =~ /-Wl,-R/) {
  941.             $libs .= ' -L$(PERL_INC) -Wl,-R$(INSTALLARCHLIB)/CORE -Wl,-R$(PERL_ARCHLIB)/CORE -lperl';
  942.         } elsif ($Config{'lddlflags'} =~ /-R/) {
  943.             $libs .= ' -L$(PERL_INC) -R$(INSTALLARCHLIB)/CORE -R$(PERL_ARCHLIB)/CORE -lperl';
  944.         }
  945.     }
  946.  
  947.     my $ld_run_path_shell = "";
  948.     if ($self->{LD_RUN_PATH} ne "") {
  949.     $ld_run_path_shell = 'LD_RUN_PATH="$(LD_RUN_PATH)" ';
  950.     }
  951.  
  952.     push @m, sprintf <<'MAKE', $ld_run_path_shell, $ldrun, $ldfrom, $libs;
  953.     %s$(LD) %s $(LDDLFLAGS) %s $(OTHERLDFLAGS) -o $@ $(MYEXTLIB)    \
  954.       $(PERL_ARCHIVE) %s $(PERL_ARCHIVE_AFTER) $(EXPORT_LIST)    \
  955.       $(INST_DYNAMIC_FIX)
  956. MAKE
  957.  
  958.     push @m, <<'MAKE';
  959.     $(CHMOD) $(PERM_RWX) $@
  960. MAKE
  961.  
  962.     return join('',@m);
  963. }
  964.  
  965. =item exescan
  966.  
  967. Deprecated method. Use libscan instead.
  968.  
  969. =cut
  970.  
  971. sub exescan {
  972.     my($self,$path) = @_;
  973.     $path;
  974. }
  975.  
  976. =item extliblist
  977.  
  978. Called by init_others, and calls ext ExtUtils::Liblist. See
  979. L<ExtUtils::Liblist> for details.
  980.  
  981. =cut
  982.  
  983. sub extliblist {
  984.     my($self,$libs) = @_;
  985.     require ExtUtils::Liblist;
  986.     $self->ext($libs, $Verbose);
  987. }
  988.  
  989. =item find_perl
  990.  
  991. Finds the executables PERL and FULLPERL
  992.  
  993. =cut
  994.  
  995. sub find_perl {
  996.     my($self, $ver, $names, $dirs, $trace) = @_;
  997.     my($name, $dir);
  998.     if ($trace >= 2){
  999.         print "Looking for perl $ver by these names:
  1000. @$names
  1001. in these dirs:
  1002. @$dirs
  1003. ";
  1004.     }
  1005.  
  1006.     my $stderr_duped = 0;
  1007.     local *STDERR_COPY;
  1008.     unless ($Is_BSD) {
  1009.         if( open(STDERR_COPY, '>&STDERR') ) {
  1010.             $stderr_duped = 1;
  1011.         }
  1012.         else {
  1013.             warn <<WARNING;
  1014. find_perl() can't dup STDERR: $!
  1015. You might see some garbage while we search for Perl
  1016. WARNING
  1017.         }
  1018.     }
  1019.  
  1020.     foreach $name (@$names){
  1021.         foreach $dir (@$dirs){
  1022.             next unless defined $dir; # $self->{PERL_SRC} may be undefined
  1023.             my ($abs, $val);
  1024.             if ($self->file_name_is_absolute($name)) {     # /foo/bar
  1025.                 $abs = $name;
  1026.             } elsif ($self->canonpath($name) eq 
  1027.                      $self->canonpath(basename($name))) {  # foo
  1028.                 $abs = $self->catfile($dir, $name);
  1029.             } else {                                            # foo/bar
  1030.                 $abs = $self->catfile($Curdir, $name);
  1031.             }
  1032.             print "Checking $abs\n" if ($trace >= 2);
  1033.             next unless $self->maybe_command($abs);
  1034.             print "Executing $abs\n" if ($trace >= 2);
  1035.  
  1036.             my $version_check = qq{$abs -le "require $ver; print qq{VER_OK}"};
  1037.             $version_check = "$Config{run} $version_check"
  1038.                 if defined $Config{run} and length $Config{run};
  1039.  
  1040.             # To avoid using the unportable 2>&1 to suppress STDERR,
  1041.             # we close it before running the command.
  1042.             # However, thanks to a thread library bug in many BSDs
  1043.             # ( http://www.freebsd.org/cgi/query-pr.cgi?pr=51535 )
  1044.             # we cannot use the fancier more portable way in here
  1045.             # but instead need to use the traditional 2>&1 construct.
  1046.             if ($Is_BSD) {
  1047.                 $val = `$version_check 2>&1`;
  1048.             } else {
  1049.                 close STDERR if $stderr_duped;
  1050.                 $val = `$version_check`;
  1051.                 open STDERR, '>&STDERR_COPY' if $stderr_duped;
  1052.             }
  1053.  
  1054.             if ($val =~ /^VER_OK/m) {
  1055.                 print "Using PERL=$abs\n" if $trace;
  1056.                 return $abs;
  1057.             } elsif ($trace >= 2) {
  1058.                 print "Result: '$val' ".($? >> 8)."\n";
  1059.             }
  1060.         }
  1061.     }
  1062.     print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
  1063.     0; # false and not empty
  1064. }
  1065.  
  1066.  
  1067. =item fixin
  1068.  
  1069.   $mm->fixin(@files);
  1070.  
  1071. Inserts the sharpbang or equivalent magic number to a set of @files.
  1072.  
  1073. =cut
  1074.  
  1075. sub fixin {    # stolen from the pink Camel book, more or less
  1076.     my ( $self, @files ) = @_;
  1077.  
  1078.     my ($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/;
  1079.     for my $file (@files) {
  1080.         my $file_new = "$file.new";
  1081.         my $file_bak = "$file.bak";
  1082.  
  1083.         local (*FIXIN);
  1084.         local (*FIXOUT);
  1085.         open( FIXIN, $file ) or croak "Can't process '$file': $!";
  1086.         local $/ = "\n";
  1087.         chomp( my $line = <FIXIN> );
  1088.         next unless $line =~ s/^\s*\#!\s*//;    # Not a shbang file.
  1089.         # Now figure out the interpreter name.
  1090.         my ( $cmd, $arg ) = split ' ', $line, 2;
  1091.         $cmd =~ s!^.*/!!;
  1092.  
  1093.         # Now look (in reverse) for interpreter in absolute PATH (unless perl).
  1094.         my $interpreter;
  1095.         if ( $cmd eq "perl" ) {
  1096.             if ( $Config{startperl} =~ m,^\#!.*/perl, ) {
  1097.                 $interpreter = $Config{startperl};
  1098.                 $interpreter =~ s,^\#!,,;
  1099.             }
  1100.             else {
  1101.                 $interpreter = $Config{perlpath};
  1102.             }
  1103.         }
  1104.         else {
  1105.             my (@absdirs)
  1106.                 = reverse grep { $self->file_name_is_absolute } $self->path;
  1107.             $interpreter = '';
  1108.             my ($dir);
  1109.             foreach $dir (@absdirs) {
  1110.                 if ( $self->maybe_command($cmd) ) {
  1111.                     warn "Ignoring $interpreter in $file\n"
  1112.                         if $Verbose && $interpreter;
  1113.                     $interpreter = $self->catfile( $dir, $cmd );
  1114.                 }
  1115.             }
  1116.         }
  1117.  
  1118.         # Figure out how to invoke interpreter on this machine.
  1119.  
  1120.         my ($shb) = "";
  1121.         if ($interpreter) {
  1122.             print STDOUT "Changing sharpbang in $file to $interpreter"
  1123.                 if $Verbose;
  1124.  
  1125.             # this is probably value-free on DOSISH platforms
  1126.             if ($does_shbang) {
  1127.                 $shb .= "$Config{'sharpbang'}$interpreter";
  1128.                 $shb .= ' ' . $arg if defined $arg;
  1129.                 $shb .= "\n";
  1130.             }
  1131.             $shb .= qq{
  1132. eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}'
  1133.     if 0; # not running under some shell
  1134. } unless $Is_Win32;    # this won't work on win32, so don't
  1135.         }
  1136.         else {
  1137.             warn "Can't find $cmd in PATH, $file unchanged"
  1138.                 if $Verbose;
  1139.             next;
  1140.         }
  1141.  
  1142.         unless ( open( FIXOUT, ">$file_new" ) ) {
  1143.             warn "Can't create new $file: $!\n";
  1144.             next;
  1145.         }
  1146.  
  1147.         # Print out the new #! line (or equivalent).
  1148.         local $\;
  1149.         local $/;
  1150.         print FIXOUT $shb, <FIXIN>;
  1151.         close FIXIN;
  1152.         close FIXOUT;
  1153.  
  1154.         chmod 0666, $file_bak;
  1155.         unlink $file_bak;
  1156.         unless ( _rename( $file, $file_bak ) ) {
  1157.             warn "Can't rename $file to $file_bak: $!";
  1158.             next;
  1159.         }
  1160.         unless ( _rename( $file_new, $file ) ) {
  1161.             warn "Can't rename $file_new to $file: $!";
  1162.             unless ( _rename( $file_bak, $file ) ) {
  1163.                 warn "Can't rename $file_bak back to $file either: $!";
  1164.                 warn "Leaving $file renamed as $file_bak\n";
  1165.             }
  1166.             next;
  1167.         }
  1168.         unlink $file_bak;
  1169.     }
  1170.     continue {
  1171.         close(FIXIN) if fileno(FIXIN);
  1172.         system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
  1173.     }
  1174. }
  1175.  
  1176.  
  1177. sub _rename {
  1178.     my($old, $new) = @_;
  1179.  
  1180.     foreach my $file ($old, $new) {
  1181.         if( $Is_VMS and basename($file) !~ /\./ ) {
  1182.             # rename() in 5.8.0 on VMS will not rename a file if it
  1183.             # does not contain a dot yet it returns success.
  1184.             $file = "$file.";
  1185.         }
  1186.     }
  1187.  
  1188.     return rename($old, $new);
  1189. }
  1190.  
  1191.  
  1192. =item force (o)
  1193.  
  1194. Writes an empty FORCE: target.
  1195.  
  1196. =cut
  1197.  
  1198. sub force {
  1199.     my($self) = shift;
  1200.     '# Phony target to force checking subdirectories.
  1201. FORCE :
  1202.     $(NOECHO) $(NOOP)
  1203. ';
  1204. }
  1205.  
  1206. =item guess_name
  1207.  
  1208. Guess the name of this package by examining the working directory's
  1209. name. MakeMaker calls this only if the developer has not supplied a
  1210. NAME attribute.
  1211.  
  1212. =cut
  1213.  
  1214. # ';
  1215.  
  1216. sub guess_name {
  1217.     my($self) = @_;
  1218.     use Cwd 'cwd';
  1219.     my $name = basename(cwd());
  1220.     $name =~ s|[\-_][\d\.\-]+\z||;  # this is new with MM 5.00, we
  1221.                                     # strip minus or underline
  1222.                                     # followed by a float or some such
  1223.     print "Warning: Guessing NAME [$name] from current directory name.\n";
  1224.     $name;
  1225. }
  1226.  
  1227. =item has_link_code
  1228.  
  1229. Returns true if C, XS, MYEXTLIB or similar objects exist within this
  1230. object that need a compiler. Does not descend into subdirectories as
  1231. needs_linking() does.
  1232.  
  1233. =cut
  1234.  
  1235. sub has_link_code {
  1236.     my($self) = shift;
  1237.     return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
  1238.     if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
  1239.     $self->{HAS_LINK_CODE} = 1;
  1240.     return 1;
  1241.     }
  1242.     return $self->{HAS_LINK_CODE} = 0;
  1243. }
  1244.  
  1245.  
  1246. =item init_dirscan
  1247.  
  1248. Scans the directory structure and initializes DIR, XS, XS_FILES,
  1249. C, C_FILES, O_FILES, H, H_FILES, PL_FILES, EXE_FILES.
  1250.  
  1251. Called by init_main.
  1252.  
  1253. =cut
  1254.  
  1255. sub init_dirscan {    # --- File and Directory Lists (.xs .pm .pod etc)
  1256.     my($self) = @_;
  1257.     my($name, %dir, %xs, %c, %h, %pl_files, %pm);
  1258.  
  1259.     my %ignore = map {( $_ => 1 )} qw(Makefile.PL Build.PL test.pl t);
  1260.  
  1261.     # ignore the distdir
  1262.     $Is_VMS ? $ignore{"$self->{DISTVNAME}.dir"} = 1
  1263.             : $ignore{$self->{DISTVNAME}} = 1;
  1264.  
  1265.     @ignore{map lc, keys %ignore} = values %ignore if $Is_VMS;
  1266.  
  1267.     foreach $name ($self->lsdir($Curdir)){
  1268.     next if $name =~ /\#/;
  1269.     next if $name eq $Curdir or $name eq $Updir or $ignore{$name};
  1270.     next unless $self->libscan($name);
  1271.     if (-d $name){
  1272.         next if -l $name; # We do not support symlinks at all
  1273.             next if $self->{NORECURS};
  1274.         $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL"));
  1275.     } elsif ($name =~ /\.xs\z/){
  1276.         my($c); ($c = $name) =~ s/\.xs\z/.c/;
  1277.         $xs{$name} = $c;
  1278.         $c{$c} = 1;
  1279.     } elsif ($name =~ /\.c(pp|xx|c)?\z/i){  # .c .C .cpp .cxx .cc
  1280.         $c{$name} = 1
  1281.         unless $name =~ m/perlmain\.c/; # See MAP_TARGET
  1282.     } elsif ($name =~ /\.h\z/i){
  1283.         $h{$name} = 1;
  1284.     } elsif ($name =~ /\.PL\z/) {
  1285.         ($pl_files{$name} = $name) =~ s/\.PL\z// ;
  1286.     } elsif (($Is_VMS || $Is_Dos) && $name =~ /[._]pl$/i) {
  1287.         # case-insensitive filesystem, one dot per name, so foo.h.PL
  1288.         # under Unix appears as foo.h_pl under VMS or fooh.pl on Dos
  1289.         local($/); open(PL,$name); my $txt = <PL>; close PL;
  1290.         if ($txt =~ /Extracting \S+ \(with variable substitutions/) {
  1291.         ($pl_files{$name} = $name) =~ s/[._]pl\z//i ;
  1292.         }
  1293.         else { 
  1294.                 $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name); 
  1295.             }
  1296.     } elsif ($name =~ /\.(p[ml]|pod)\z/){
  1297.         $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name);
  1298.     }
  1299.     }
  1300.  
  1301.     $self->{PL_FILES}   ||= \%pl_files;
  1302.     $self->{DIR}        ||= [sort keys %dir];
  1303.     $self->{XS}         ||= \%xs;
  1304.     $self->{C}          ||= [sort keys %c];
  1305.     $self->{H}          ||= [sort keys %h];
  1306.     $self->{PM}         ||= \%pm;
  1307.  
  1308.     my @o_files = @{$self->{C}};
  1309.     $self->{O_FILES} = [grep s/\.c(pp|xx|c)?\z/$self->{OBJ_EXT}/i, @o_files];
  1310. }
  1311.  
  1312.  
  1313. =item init_MANPODS
  1314.  
  1315. Determines if man pages should be generated and initializes MAN1PODS
  1316. and MAN3PODS as appropriate.
  1317.  
  1318. =cut
  1319.  
  1320. sub init_MANPODS {
  1321.     my $self = shift;
  1322.  
  1323.     # Set up names of manual pages to generate from pods
  1324.     foreach my $man (qw(MAN1 MAN3)) {
  1325.     if ( $self->{"${man}PODS"}
  1326.              or $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/
  1327.         ) {
  1328.             $self->{"${man}PODS"} ||= {};
  1329.         }
  1330.         else {
  1331.             my $init_method = "init_${man}PODS";
  1332.             $self->$init_method();
  1333.     }
  1334.     }
  1335. }
  1336.  
  1337.  
  1338. sub _has_pod {
  1339.     my($self, $file) = @_;
  1340.  
  1341.     local *FH;
  1342.     my($ispod)=0;
  1343.     if (open(FH,"<$file")) {
  1344.     while (<FH>) {
  1345.         if (/^=(?:head\d+|item|pod)\b/) {
  1346.         $ispod=1;
  1347.         last;
  1348.         }
  1349.     }
  1350.     close FH;
  1351.     } else {
  1352.     # If it doesn't exist yet, we assume, it has pods in it
  1353.     $ispod = 1;
  1354.     }
  1355.  
  1356.     return $ispod;
  1357. }
  1358.  
  1359.  
  1360. =item init_MAN1PODS
  1361.  
  1362. Initializes MAN1PODS from the list of EXE_FILES.
  1363.  
  1364. =cut
  1365.  
  1366. sub init_MAN1PODS {
  1367.     my($self) = @_;
  1368.  
  1369.     if ( exists $self->{EXE_FILES} ) {
  1370.     foreach my $name (@{$self->{EXE_FILES}}) {
  1371.         next unless $self->_has_pod($name);
  1372.  
  1373.         $self->{MAN1PODS}->{$name} =
  1374.         $self->catfile("\$(INST_MAN1DIR)", 
  1375.                    basename($name).".\$(MAN1EXT)");
  1376.     }
  1377.     }
  1378. }
  1379.  
  1380.  
  1381. =item init_MAN3PODS
  1382.  
  1383. Initializes MAN3PODS from the list of PM files.
  1384.  
  1385. =cut
  1386.  
  1387. sub init_MAN3PODS {
  1388.     my $self = shift;
  1389.  
  1390.     my %manifypods = (); # we collect the keys first, i.e. the files
  1391.                          # we have to convert to pod
  1392.  
  1393.     foreach my $name (keys %{$self->{PM}}) {
  1394.     if ($name =~ /\.pod\z/ ) {
  1395.         $manifypods{$name} = $self->{PM}{$name};
  1396.     } elsif ($name =~ /\.p[ml]\z/ ) {
  1397.         if( $self->_has_pod($name) ) {
  1398.         $manifypods{$name} = $self->{PM}{$name};
  1399.         }
  1400.     }
  1401.     }
  1402.  
  1403.     my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
  1404.  
  1405.     # Remove "Configure.pm" and similar, if it's not the only pod listed
  1406.     # To force inclusion, just name it "Configure.pod", or override 
  1407.     # MAN3PODS
  1408.     foreach my $name (keys %manifypods) {
  1409.     if ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) {
  1410.         delete $manifypods{$name};
  1411.         next;
  1412.     }
  1413.     my($manpagename) = $name;
  1414.     $manpagename =~ s/\.p(od|m|l)\z//;
  1415.     # everything below lib is ok
  1416.     unless($manpagename =~ s!^\W*($parentlibs_re)\W+!!s) {
  1417.         $manpagename = $self->catfile(
  1418.             split(/::/,$self->{PARENT_NAME}),$manpagename
  1419.         );
  1420.     }
  1421.     $manpagename = $self->replace_manpage_separator($manpagename);
  1422.     $self->{MAN3PODS}->{$name} =
  1423.         $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)");
  1424.     }
  1425. }
  1426.  
  1427.  
  1428. =item init_PM
  1429.  
  1430. Initializes PMLIBDIRS and PM from PMLIBDIRS.
  1431.  
  1432. =cut
  1433.  
  1434. sub init_PM {
  1435.     my $self = shift;
  1436.  
  1437.     # Some larger extensions often wish to install a number of *.pm/pl
  1438.     # files into the library in various locations.
  1439.  
  1440.     # The attribute PMLIBDIRS holds an array reference which lists
  1441.     # subdirectories which we should search for library files to
  1442.     # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
  1443.     # recursively search through the named directories (skipping any
  1444.     # which don't exist or contain Makefile.PL files).
  1445.  
  1446.     # For each *.pm or *.pl file found $self->libscan() is called with
  1447.     # the default installation path in $_[1]. The return value of
  1448.     # libscan defines the actual installation location.  The default
  1449.     # libscan function simply returns the path.  The file is skipped
  1450.     # if libscan returns false.
  1451.  
  1452.     # The default installation location passed to libscan in $_[1] is:
  1453.     #
  1454.     #  ./*.pm        => $(INST_LIBDIR)/*.pm
  1455.     #  ./xyz/...    => $(INST_LIBDIR)/xyz/...
  1456.     #  ./lib/...    => $(INST_LIB)/...
  1457.     #
  1458.     # In this way the 'lib' directory is seen as the root of the actual
  1459.     # perl library whereas the others are relative to INST_LIBDIR
  1460.     # (which includes PARENT_NAME). This is a subtle distinction but one
  1461.     # that's important for nested modules.
  1462.  
  1463.     unless( $self->{PMLIBDIRS} ) {
  1464.         if( $Is_VMS ) {
  1465.             # Avoid logical name vs directory collisions
  1466.             $self->{PMLIBDIRS} = ['./lib', "./$self->{BASEEXT}"];
  1467.         }
  1468.         else {
  1469.             $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}];
  1470.         }
  1471.     }
  1472.  
  1473.     #only existing directories that aren't in $dir are allowed
  1474.  
  1475.     # Avoid $_ wherever possible:
  1476.     # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
  1477.     my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
  1478.     @{$self->{PMLIBDIRS}} = ();
  1479.     my %dir = map { ($_ => $_) } @{$self->{DIR}};
  1480.     foreach my $pmlibdir (@pmlibdirs) {
  1481.     -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
  1482.     }
  1483.  
  1484.     unless( $self->{PMLIBPARENTDIRS} ) {
  1485.     @{$self->{PMLIBPARENTDIRS}} = ('lib');
  1486.     }
  1487.  
  1488.     return if $self->{PM} and $self->{ARGS}{PM};
  1489.  
  1490.     if (@{$self->{PMLIBDIRS}}){
  1491.     print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
  1492.         if ($Verbose >= 2);
  1493.     require File::Find;
  1494.         File::Find::find(sub {
  1495.             if (-d $_){
  1496.                 unless ($self->libscan($_)){
  1497.                     $File::Find::prune = 1;
  1498.                 }
  1499.                 return;
  1500.             }
  1501.             return if /\#/;
  1502.             return if /~$/;    # emacs temp files
  1503.             return if /,v$/;   # RCS files
  1504.  
  1505.         my $path   = $File::Find::name;
  1506.             my $prefix = $self->{INST_LIBDIR};
  1507.             my $striplibpath;
  1508.  
  1509.         my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
  1510.         $prefix =  $self->{INST_LIB} 
  1511.                 if ($striplibpath = $path) =~ s{^(\W*)($parentlibs_re)\W}
  1512.                                            {$1}i;
  1513.  
  1514.         my($inst) = $self->catfile($prefix,$striplibpath);
  1515.         local($_) = $inst; # for backwards compatibility
  1516.         $inst = $self->libscan($inst);
  1517.         print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
  1518.         return unless $inst;
  1519.         $self->{PM}{$path} = $inst;
  1520.     }, @{$self->{PMLIBDIRS}});
  1521.     }
  1522. }
  1523.  
  1524.  
  1525. =item init_DIRFILESEP
  1526.  
  1527. Using / for Unix.  Called by init_main.
  1528.  
  1529. =cut
  1530.  
  1531. sub init_DIRFILESEP {
  1532.     my($self) = shift;
  1533.  
  1534.     $self->{DIRFILESEP} = '/';
  1535. }
  1536.     
  1537.  
  1538. =item init_main
  1539.  
  1540. Initializes AR, AR_STATIC_ARGS, BASEEXT, CONFIG, DISTNAME, DLBASE,
  1541. EXE_EXT, FULLEXT, FULLPERL, FULLPERLRUN, FULLPERLRUNINST, INST_*,
  1542. INSTALL*, INSTALLDIRS, LIB_EXT, LIBPERL_A, MAP_TARGET, NAME,
  1543. OBJ_EXT, PARENT_NAME, PERL, PERL_ARCHLIB, PERL_INC, PERL_LIB,
  1544. PERL_SRC, PERLRUN, PERLRUNINST, PREFIX, VERSION,
  1545. VERSION_SYM, XS_VERSION.
  1546.  
  1547. =cut
  1548.  
  1549. sub init_main {
  1550.     my($self) = @_;
  1551.  
  1552.     # --- Initialize Module Name and Paths
  1553.  
  1554.     # NAME    = Foo::Bar::Oracle
  1555.     # FULLEXT = Foo/Bar/Oracle
  1556.     # BASEEXT = Oracle
  1557.     # PARENT_NAME = Foo::Bar
  1558. ### Only UNIX:
  1559. ###    ($self->{FULLEXT} =
  1560. ###     $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
  1561.     $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
  1562.  
  1563.  
  1564.     # Copied from DynaLoader:
  1565.  
  1566.     my(@modparts) = split(/::/,$self->{NAME});
  1567.     my($modfname) = $modparts[-1];
  1568.  
  1569.     # Some systems have restrictions on files names for DLL's etc.
  1570.     # mod2fname returns appropriate file base name (typically truncated)
  1571.     # It may also edit @modparts if required.
  1572.     if (defined &DynaLoader::mod2fname) {
  1573.         $modfname = &DynaLoader::mod2fname(\@modparts);
  1574.     }
  1575.  
  1576.     ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!(?:([\w:]+)::)?(\w+)\z! ;
  1577.     $self->{PARENT_NAME} ||= '';
  1578.  
  1579.     if (defined &DynaLoader::mod2fname) {
  1580.     # As of 5.001m, dl_os2 appends '_'
  1581.     $self->{DLBASE} = $modfname;
  1582.     } else {
  1583.     $self->{DLBASE} = '$(BASEEXT)';
  1584.     }
  1585.  
  1586.  
  1587.     # --- Initialize PERL_LIB, PERL_SRC
  1588.  
  1589.     # *Real* information: where did we get these two from? ...
  1590.     my $inc_config_dir = dirname($INC{'Config.pm'});
  1591.     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
  1592.  
  1593.     unless ($self->{PERL_SRC}){
  1594.         foreach my $dir_count (1..8) { # 8 is the VMS limit for nesting
  1595.             my $dir = $self->catdir(($Updir) x $dir_count);
  1596.  
  1597.             if (-f $self->catfile($dir,"config_h.SH")   &&
  1598.                 -f $self->catfile($dir,"perl.h")        &&
  1599.                 -f $self->catfile($dir,"lib","Exporter.pm")
  1600.             ) {
  1601.                 $self->{PERL_SRC}=$dir ;
  1602.                 last;
  1603.             }
  1604.         }
  1605.     }
  1606.  
  1607.     warn "PERL_CORE is set but I can't find your PERL_SRC!\n" if
  1608.       $self->{PERL_CORE} and !$self->{PERL_SRC};
  1609.  
  1610.     if ($self->{PERL_SRC}){
  1611.     $self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
  1612.  
  1613.         if (defined $Cross::platform) {
  1614.             $self->{PERL_ARCHLIB} = 
  1615.               $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform);
  1616.             $self->{PERL_INC}     = 
  1617.               $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform, 
  1618.                                  $Is_Win32?("CORE"):());
  1619.         }
  1620.         else {
  1621.             $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
  1622.             $self->{PERL_INC}     = ($Is_Win32) ? 
  1623.               $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
  1624.         }
  1625.  
  1626.     # catch a situation that has occurred a few times in the past:
  1627.     unless (
  1628.         -s $self->catfile($self->{PERL_SRC},'cflags')
  1629.         or
  1630.         $Is_VMS
  1631.         &&
  1632.         -s $self->catfile($self->{PERL_SRC},'perlshr_attr.opt')
  1633.         or
  1634.         $Is_Win32
  1635.            ){
  1636.         warn qq{
  1637. You cannot build extensions below the perl source tree after executing
  1638. a 'make clean' in the perl source tree.
  1639.  
  1640. To rebuild extensions distributed with the perl source you should
  1641. simply Configure (to include those extensions) and then build perl as
  1642. normal. After installing perl the source tree can be deleted. It is
  1643. not needed for building extensions by running 'perl Makefile.PL'
  1644. usually without extra arguments.
  1645.  
  1646. It is recommended that you unpack and build additional extensions away
  1647. from the perl source tree.
  1648. };
  1649.     }
  1650.     } else {
  1651.     # we should also consider $ENV{PERL5LIB} here
  1652.         my $old = $self->{PERL_LIB} || $self->{PERL_ARCHLIB} || $self->{PERL_INC};
  1653.     $self->{PERL_LIB}     ||= $Config{privlibexp};
  1654.     $self->{PERL_ARCHLIB} ||= $Config{archlibexp};
  1655.     $self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
  1656.     my $perl_h;
  1657.  
  1658.     if (not -f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))
  1659.         and not $old){
  1660.         # Maybe somebody tries to build an extension with an
  1661.         # uninstalled Perl outside of Perl build tree
  1662.         my $lib;
  1663.         for my $dir (@INC) {
  1664.           $lib = $dir, last if -e $self->catdir($dir, "Config.pm");
  1665.         }
  1666.         if ($lib) {
  1667.               # Win32 puts its header files in /perl/src/lib/CORE.
  1668.               # Unix leaves them in /perl/src.
  1669.           my $inc = $Is_Win32 ? $self->catdir($lib, "CORE" )
  1670.                                   : dirname $lib;
  1671.           if (-e $self->catdir($inc, "perl.h")) {
  1672.         $self->{PERL_LIB}       = $lib;
  1673.         $self->{PERL_ARCHLIB}       = $lib;
  1674.         $self->{PERL_INC}       = $inc;
  1675.         $self->{UNINSTALLED_PERL}  = 1;
  1676.         print STDOUT <<EOP;
  1677. ... Detected uninstalled Perl.  Trying to continue.
  1678. EOP
  1679.           }
  1680.         }
  1681.     }    
  1682.     }
  1683.  
  1684.     # We get SITELIBEXP and SITEARCHEXP directly via
  1685.     # Get_from_Config. When we are running standard modules, these
  1686.     # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
  1687.     # set it to "site". I prefer that INSTALLDIRS be set from outside
  1688.     # MakeMaker.
  1689.     $self->{INSTALLDIRS} ||= "site";
  1690.  
  1691.     $self->{MAN1EXT} ||= $Config{man1ext};
  1692.     $self->{MAN3EXT} ||= $Config{man3ext};
  1693.  
  1694.     # Get some stuff out of %Config if we haven't yet done so
  1695.     print STDOUT "CONFIG must be an array ref\n"
  1696.     if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
  1697.     $self->{CONFIG} = [] unless (ref $self->{CONFIG});
  1698.     push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
  1699.     push(@{$self->{CONFIG}}, 'shellflags') if $Config{shellflags};
  1700.     my(%once_only);
  1701.     foreach my $m (@{$self->{CONFIG}}){
  1702.     next if $once_only{$m};
  1703.     print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
  1704.         unless exists $Config{$m};
  1705.     $self->{uc $m} ||= $Config{$m};
  1706.     $once_only{$m} = 1;
  1707.     }
  1708.  
  1709. # This is too dangerous:
  1710. #    if ($^O eq "next") {
  1711. #    $self->{AR} = "libtool";
  1712. #    $self->{AR_STATIC_ARGS} = "-o";
  1713. #    }
  1714. # But I leave it as a placeholder
  1715.  
  1716.     $self->{AR_STATIC_ARGS} ||= "cr";
  1717.  
  1718.     # These should never be needed
  1719.     $self->{OBJ_EXT} ||= '.o';
  1720.     $self->{LIB_EXT} ||= '.a';
  1721.  
  1722.     $self->{MAP_TARGET} ||= "perl";
  1723.  
  1724.     $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
  1725.  
  1726.     # make a simple check if we find Exporter
  1727.     warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
  1728.         (Exporter.pm not found)"
  1729.     unless -f $self->catfile("$self->{PERL_LIB}","Exporter.pm") ||
  1730.         $self->{NAME} eq "ExtUtils::MakeMaker";
  1731. }
  1732.  
  1733. =item init_others
  1734.  
  1735. Initializes EXTRALIBS, BSLOADLIBS, LDLOADLIBS, LIBS, LD_RUN_PATH, LD,
  1736. OBJECT, BOOTDEP, PERLMAINCC, LDFROM, LINKTYPE, SHELL, NOOP,
  1737. FIRST_MAKEFILE, MAKEFILE_OLD, NOECHO, RM_F, RM_RF, TEST_F,
  1738. TOUCH, CP, MV, CHMOD, UMASK_NULL, ECHO, ECHO_N
  1739.  
  1740. =cut
  1741.  
  1742. sub init_others {    # --- Initialize Other Attributes
  1743.     my($self) = shift;
  1744.  
  1745.     $self->{LD} ||= 'ld';
  1746.  
  1747.     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
  1748.     # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
  1749.     # undefined. In any case we turn it into an anon array:
  1750.  
  1751.     # May check $Config{libs} too, thus not empty.
  1752.     $self->{LIBS} = [$self->{LIBS}] unless ref $self->{LIBS};
  1753.  
  1754.     $self->{LIBS} = [''] unless @{$self->{LIBS}} && defined $self->{LIBS}[0];
  1755.     $self->{LD_RUN_PATH} = "";
  1756.     my($libs);
  1757.     foreach $libs ( @{$self->{LIBS}} ){
  1758.     $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
  1759.     my(@libs) = $self->extliblist($libs);
  1760.     if ($libs[0] or $libs[1] or $libs[2]){
  1761.         # LD_RUN_PATH now computed by ExtUtils::Liblist
  1762.         ($self->{EXTRALIBS},  $self->{BSLOADLIBS}, 
  1763.              $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
  1764.         last;
  1765.     }
  1766.     }
  1767.  
  1768.     if ( $self->{OBJECT} ) {
  1769.     $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
  1770.     } else {
  1771.     # init_dirscan should have found out, if we have C files
  1772.     $self->{OBJECT} = "";
  1773.     $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
  1774.     }
  1775.     $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
  1776.     $self->{BOOTDEP}  = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
  1777.     $self->{PERLMAINCC} ||= '$(CC)';
  1778.     $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
  1779.  
  1780.     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
  1781.     # the 'dynamic' section of MM.  We don't have this problem with
  1782.     # 'static', since we either must use it (%Config says we can't
  1783.     # use dynamic loading) or the caller asked for it explicitly.
  1784.     if (!$self->{LINKTYPE}) {
  1785.        $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
  1786.                         ? 'static'
  1787.                         : ($Config{usedl} ? 'dynamic' : 'static');
  1788.     };
  1789.  
  1790.     $self->{NOOP}               ||= '$(SHELL) -c true';
  1791.     $self->{NOECHO}             = '@' unless defined $self->{NOECHO};
  1792.  
  1793.     $self->{FIRST_MAKEFILE}     ||= $self->{MAKEFILE} || 'Makefile';
  1794.     $self->{MAKEFILE}           ||= $self->{FIRST_MAKEFILE};
  1795.     $self->{MAKEFILE_OLD}       ||= $self->{MAKEFILE}.'.old';
  1796.     $self->{MAKE_APERL_FILE}    ||= $self->{MAKEFILE}.'.aperl';
  1797.  
  1798.     # Some makes require a wrapper around macros passed in on the command 
  1799.     # line.
  1800.     $self->{MACROSTART}         ||= '';
  1801.     $self->{MACROEND}           ||= '';
  1802.  
  1803.     # Not everybody uses -f to indicate "use this Makefile instead"
  1804.     $self->{USEMAKEFILE}        ||= '-f';
  1805.  
  1806.     $self->{SHELL}              ||= $Config{sh} || '/bin/sh';
  1807.  
  1808.     $self->{ECHO}       ||= 'echo';
  1809.     $self->{ECHO_N}     ||= 'echo -n';
  1810.     $self->{RM_F}       ||= "rm -f";
  1811.     $self->{RM_RF}      ||= "rm -rf";
  1812.     $self->{TOUCH}      ||= "touch";
  1813.     $self->{TEST_F}     ||= "test -f";
  1814.     $self->{CP}         ||= "cp";
  1815.     $self->{MV}         ||= "mv";
  1816.     $self->{CHMOD}      ||= "chmod";
  1817.     $self->{MKPATH}     ||= '$(ABSPERLRUN) "-MExtUtils::Command" -e mkpath';
  1818.     $self->{EQUALIZE_TIMESTAMP} ||= 
  1819.       '$(ABSPERLRUN) "-MExtUtils::Command" -e eqtime';
  1820.  
  1821.     $self->{UNINST}     ||= 0;
  1822.     $self->{VERBINST}   ||= 0;
  1823.     $self->{MOD_INSTALL} ||= 
  1824.       $self->oneliner(<<'CODE', ['-MExtUtils::Install']);
  1825. install({@ARGV}, '$(VERBINST)', 0, '$(UNINST)');
  1826. CODE
  1827.     $self->{DOC_INSTALL}        ||= 
  1828.       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e perllocal_install';
  1829.     $self->{UNINSTALL}          ||= 
  1830.       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e uninstall';
  1831.     $self->{WARN_IF_OLD_PACKLIST} ||= 
  1832.       '$(ABSPERLRUN) "-MExtUtils::Command::MM" -e warn_if_old_packlist';
  1833.     $self->{FIXIN}              ||= 
  1834.       q{$(PERLRUN) "-MExtUtils::MY" -e "MY->fixin(shift)"};
  1835.  
  1836.     $self->{UMASK_NULL}         ||= "umask 0";
  1837.     $self->{DEV_NULL}           ||= "> /dev/null 2>&1";
  1838.  
  1839.     return 1;
  1840. }
  1841.  
  1842.  
  1843. =item init_linker
  1844.  
  1845. Unix has no need of special linker flags.
  1846.  
  1847. =cut
  1848.  
  1849. sub init_linker {
  1850.     my($self) = shift;
  1851.     $self->{PERL_ARCHIVE} ||= '';
  1852.     $self->{PERL_ARCHIVE_AFTER} ||= '';
  1853.     $self->{EXPORT_LIST}  ||= '';
  1854. }
  1855.  
  1856.  
  1857. =begin _protected
  1858.  
  1859. =item init_lib2arch
  1860.  
  1861.     $mm->init_lib2arch
  1862.  
  1863. =end _protected
  1864.  
  1865. =cut
  1866.  
  1867. sub init_lib2arch {
  1868.     my($self) = shift;
  1869.  
  1870.     # The user who requests an installation directory explicitly
  1871.     # should not have to tell us an architecture installation directory
  1872.     # as well. We look if a directory exists that is named after the
  1873.     # architecture. If not we take it as a sign that it should be the
  1874.     # same as the requested installation directory. Otherwise we take
  1875.     # the found one.
  1876.     for my $libpair ({l=>"privlib",   a=>"archlib"}, 
  1877.                      {l=>"sitelib",   a=>"sitearch"},
  1878.                      {l=>"vendorlib", a=>"vendorarch"},
  1879.                     )
  1880.     {
  1881.         my $lib = "install$libpair->{l}";
  1882.         my $Lib = uc $lib;
  1883.         my $Arch = uc "install$libpair->{a}";
  1884.         if( $self->{$Lib} && ! $self->{$Arch} ){
  1885.             my($ilib) = $Config{$lib};
  1886.  
  1887.             $self->prefixify($Arch,$ilib,$self->{$Lib});
  1888.  
  1889.             unless (-d $self->{$Arch}) {
  1890.                 print STDOUT "Directory $self->{$Arch} not found\n" 
  1891.                   if $Verbose;
  1892.                 $self->{$Arch} = $self->{$Lib};
  1893.             }
  1894.             print STDOUT "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
  1895.         }
  1896.     }
  1897. }
  1898.  
  1899.  
  1900. =item init_PERL
  1901.  
  1902.     $mm->init_PERL;
  1903.  
  1904. Called by init_main.  Sets up ABSPERL, PERL, FULLPERL and all the
  1905. *PERLRUN* permutations.
  1906.  
  1907.     PERL is allowed to be miniperl
  1908.     FULLPERL must be a complete perl
  1909.  
  1910.     ABSPERL is PERL converted to an absolute path
  1911.  
  1912.     *PERLRUN contains everything necessary to run perl, find it's
  1913.          libraries, etc...
  1914.  
  1915.     *PERLRUNINST is *PERLRUN + everything necessary to find the
  1916.          modules being built.
  1917.  
  1918. =cut
  1919.  
  1920. sub init_PERL {
  1921.     my($self) = shift;
  1922.  
  1923.     my @defpath = ();
  1924.     foreach my $component ($self->{PERL_SRC}, $self->path(), 
  1925.                            $Config{binexp}) 
  1926.     {
  1927.     push @defpath, $component if defined $component;
  1928.     }
  1929.  
  1930.     # Build up a set of file names (not command names).
  1931.     my $thisperl = $self->canonpath($^X);
  1932.     $thisperl .= $Config{exe_ext} unless 
  1933.                 # VMS might have a file version # at the end
  1934.       $Is_VMS ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i
  1935.               : $thisperl =~ m/$Config{exe_ext}$/i;
  1936.  
  1937.     # We need a relative path to perl when in the core.
  1938.     $thisperl = $self->abs2rel($thisperl) if $self->{PERL_CORE};
  1939.  
  1940.     my @perls = ($thisperl);
  1941.     push @perls, map { "$_$Config{exe_ext}" }
  1942.                      ('perl', 'perl5', "perl$Config{version}");
  1943.  
  1944.     # miniperl has priority over all but the cannonical perl when in the
  1945.     # core.  Otherwise its a last resort.
  1946.     my $miniperl = "miniperl$Config{exe_ext}";
  1947.     if( $self->{PERL_CORE} ) {
  1948.         splice @perls, 1, 0, $miniperl;
  1949.     }
  1950.     else {
  1951.         push @perls, $miniperl;
  1952.     }
  1953.  
  1954.     $self->{PERL} ||=
  1955.         $self->find_perl(5.0, \@perls, \@defpath, $Verbose );
  1956.     # don't check if perl is executable, maybe they have decided to
  1957.     # supply switches with perl
  1958.  
  1959.     # When built for debugging, VMS doesn't create perl.exe but ndbgperl.exe.
  1960.     my $perl_name = 'perl';
  1961.     $perl_name = 'ndbgperl' if $Is_VMS && 
  1962.       defined $Config{usevmsdebug} && $Config{usevmsdebug} eq 'define';
  1963.  
  1964.     # XXX This logic is flawed.  If "miniperl" is anywhere in the path
  1965.     # it will get confused.  It should be fixed to work only on the filename.
  1966.     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
  1967.     ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/$perl_name/i
  1968.     unless $self->{FULLPERL};
  1969.  
  1970.     # Little hack to get around VMS's find_perl putting "MCR" in front
  1971.     # sometimes.
  1972.     $self->{ABSPERL} = $self->{PERL};
  1973.     my $has_mcr = $self->{ABSPERL} =~ s/^MCR\s*//;
  1974.     if( $self->file_name_is_absolute($self->{ABSPERL}) ) {
  1975.         $self->{ABSPERL} = '$(PERL)';
  1976.     }
  1977.     else {
  1978.         $self->{ABSPERL} = $self->rel2abs($self->{ABSPERL});
  1979.         $self->{ABSPERL} = 'MCR '.$self->{ABSPERL} if $has_mcr;
  1980.     }
  1981.  
  1982.     # Are we building the core?
  1983.     $self->{PERL_CORE} = $ENV{PERL_CORE} unless exists $self->{PERL_CORE};
  1984.     $self->{PERL_CORE} = 0               unless defined $self->{PERL_CORE};
  1985.  
  1986.     # How do we run perl?
  1987.     foreach my $perl (qw(PERL FULLPERL ABSPERL)) {
  1988.         my $run  = $perl.'RUN';
  1989.  
  1990.         $self->{$run}  = "\$($perl)";
  1991.  
  1992.         # Make sure perl can find itself before it's installed.
  1993.         $self->{$run} .= q{ "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"} 
  1994.           if $self->{UNINSTALLED_PERL} || $self->{PERL_CORE};
  1995.  
  1996.         $self->{$perl.'RUNINST'} = 
  1997.           sprintf q{$(%sRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)"}, $perl;
  1998.     }
  1999.  
  2000.     return 1;
  2001. }
  2002.  
  2003.  
  2004. =item init_platform
  2005.  
  2006. =item platform_constants
  2007.  
  2008. Add MM_Unix_VERSION.
  2009.  
  2010. =cut
  2011.  
  2012. sub init_platform {
  2013.     my($self) = shift;
  2014.  
  2015.     $self->{MM_Unix_VERSION} = $VERSION;
  2016.     $self->{PERL_MALLOC_DEF} = '-DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc '.
  2017.                                '-Dfree=Perl_mfree -Drealloc=Perl_realloc '.
  2018.                                '-Dcalloc=Perl_calloc';
  2019.  
  2020. }
  2021.  
  2022. sub platform_constants {
  2023.     my($self) = shift;
  2024.     my $make_frag = '';
  2025.  
  2026.     foreach my $macro (qw(MM_Unix_VERSION PERL_MALLOC_DEF))
  2027.     {
  2028.         next unless defined $self->{$macro};
  2029.         $make_frag .= "$macro = $self->{$macro}\n";
  2030.     }
  2031.  
  2032.     return $make_frag;
  2033. }
  2034.  
  2035.  
  2036. =item init_PERM
  2037.  
  2038.   $mm->init_PERM
  2039.  
  2040. Called by init_main.  Initializes PERL_*
  2041.  
  2042. =cut
  2043.  
  2044. sub init_PERM {
  2045.     my($self) = shift;
  2046.  
  2047.     $self->{PERM_RW}  = 644  unless defined $self->{PERM_RW};
  2048.     $self->{PERM_RWX} = 755  unless defined $self->{PERM_RWX};
  2049.  
  2050.     return 1;
  2051. }
  2052.  
  2053.  
  2054. =item init_xs
  2055.  
  2056.     $mm->init_xs
  2057.  
  2058. Sets up macros having to do with XS code.  Currently just INST_STATIC,
  2059. INST_DYNAMIC and INST_BOOT.
  2060.  
  2061. =cut
  2062.  
  2063. sub init_xs {
  2064.     my $self = shift;
  2065.  
  2066.     if ($self->has_link_code()) {
  2067.         $self->{INST_STATIC}  = 
  2068.           $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT)$(LIB_EXT)');
  2069.         $self->{INST_DYNAMIC} = 
  2070.           $self->catfile('$(INST_ARCHAUTODIR)', '$(DLBASE).$(DLEXT)');
  2071.         $self->{INST_BOOT}    = 
  2072.           $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT).bs');
  2073.     } else {
  2074.         $self->{INST_STATIC}  = '';
  2075.         $self->{INST_DYNAMIC} = '';
  2076.         $self->{INST_BOOT}    = '';
  2077.     }
  2078. }    
  2079.  
  2080. =item install (o)
  2081.  
  2082. Defines the install target.
  2083.  
  2084. =cut
  2085.  
  2086. sub install {
  2087.     my($self, %attribs) = @_;
  2088.     my(@m);
  2089.  
  2090.     push @m, q{
  2091. install :: pure_install doc_install
  2092.     $(NOECHO) $(NOOP)
  2093.  
  2094. install_perl :: pure_perl_install doc_perl_install
  2095.     $(NOECHO) $(NOOP)
  2096.  
  2097. install_site :: pure_site_install doc_site_install
  2098.     $(NOECHO) $(NOOP)
  2099.  
  2100. install_vendor :: pure_vendor_install doc_vendor_install
  2101.     $(NOECHO) $(NOOP)
  2102.  
  2103. pure_install :: pure_$(INSTALLDIRS)_install
  2104.     $(NOECHO) $(NOOP)
  2105.  
  2106. doc_install :: doc_$(INSTALLDIRS)_install
  2107.     $(NOECHO) $(NOOP)
  2108.  
  2109. pure__install : pure_site_install
  2110.     $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
  2111.  
  2112. doc__install : doc_site_install
  2113.     $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
  2114.  
  2115. pure_perl_install :: all
  2116.     $(NOECHO) umask 022; $(MOD_INSTALL) \
  2117.         $(INST_LIB) $(DESTINSTALLPRIVLIB) \
  2118.         $(INST_ARCHLIB) $(DESTINSTALLARCHLIB) \
  2119.         $(INST_BIN) $(DESTINSTALLBIN) \
  2120.         $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \
  2121.         $(INST_MAN1DIR) $(DESTINSTALLMAN1DIR) \
  2122.         $(INST_MAN3DIR) $(DESTINSTALLMAN3DIR)
  2123.     $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
  2124.         }.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{
  2125.  
  2126.  
  2127. pure_site_install :: all
  2128.     $(NOECHO) umask 02; $(MOD_INSTALL) \
  2129.         read }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
  2130.         write }.$self->catfile('$(DESTINSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{ \
  2131.         $(INST_LIB) $(DESTINSTALLSITELIB) \
  2132.         $(INST_ARCHLIB) $(DESTINSTALLSITEARCH) \
  2133.         $(INST_BIN) $(DESTINSTALLSITEBIN) \
  2134.         $(INST_SCRIPT) $(DESTINSTALLSITESCRIPT) \
  2135.         $(INST_MAN1DIR) $(DESTINSTALLSITEMAN1DIR) \
  2136.         $(INST_MAN3DIR) $(DESTINSTALLSITEMAN3DIR)
  2137.     $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
  2138.         }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{
  2139.  
  2140. pure_vendor_install :: all
  2141.     $(NOECHO) umask 022; $(MOD_INSTALL) \
  2142.         $(INST_LIB) $(DESTINSTALLVENDORLIB) \
  2143.         $(INST_ARCHLIB) $(DESTINSTALLVENDORARCH) \
  2144.         $(INST_BIN) $(DESTINSTALLVENDORBIN) \
  2145.         $(INST_SCRIPT) $(DESTINSTALLVENDORSCRIPT) \
  2146.         $(INST_MAN1DIR) $(DESTINSTALLVENDORMAN1DIR) \
  2147.         $(INST_MAN3DIR) $(DESTINSTALLVENDORMAN3DIR)
  2148.  
  2149. doc_perl_install :: all
  2150.  
  2151. doc_site_install :: all
  2152.     $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLSITEARCH)/perllocal.pod
  2153.     -$(NOECHO) umask 02; $(MKPATH) $(DESTINSTALLSITEARCH)
  2154.     -$(NOECHO) umask 02; $(DOC_INSTALL) \
  2155.         "Module" "$(NAME)" \
  2156.         "installed into" "$(INSTALLSITELIB)" \
  2157.         LINKTYPE "$(LINKTYPE)" \
  2158.         VERSION "$(VERSION)" \
  2159.         EXE_FILES "$(EXE_FILES)" \
  2160.         >> }.$self->catfile('$(DESTINSTALLSITEARCH)','perllocal.pod').q{
  2161.  
  2162. doc_vendor_install :: all
  2163.  
  2164. };
  2165.  
  2166.     push @m, q{
  2167. uninstall :: uninstall_from_$(INSTALLDIRS)dirs
  2168.     $(NOECHO) $(NOOP)
  2169.  
  2170. uninstall_from_perldirs ::
  2171.  
  2172. uninstall_from_sitedirs ::
  2173.     $(NOECHO) $(UNINSTALL) }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{
  2174.  
  2175. uninstall_from_vendordirs ::
  2176.  
  2177. };
  2178.  
  2179.     join("",@m);
  2180. }
  2181.  
  2182. =item installbin (o)
  2183.  
  2184. Defines targets to make and to install EXE_FILES.
  2185.  
  2186. =cut
  2187.  
  2188. sub installbin {
  2189.     my($self) = shift;
  2190.  
  2191.     return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
  2192.     my @exefiles = @{$self->{EXE_FILES}};
  2193.     return "" unless @exefiles;
  2194.  
  2195.     @exefiles = map vmsify($_), @exefiles if $Is_VMS;
  2196.  
  2197.     my %fromto;
  2198.     for my $from (@exefiles) {
  2199.     my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
  2200.  
  2201.     local($_) = $path; # for backwards compatibility
  2202.     my $to = $self->libscan($path);
  2203.     print "libscan($from) => '$to'\n" if ($Verbose >=2);
  2204.  
  2205.         $to = vmsify($to) if $Is_VMS;
  2206.     $fromto{$from} = $to;
  2207.     }
  2208.     my @to   = values %fromto;
  2209.  
  2210.     my @m;
  2211.     push(@m, qq{
  2212. EXE_FILES = @exefiles
  2213.  
  2214. pure_all :: @to
  2215.     \$(NOECHO) \$(NOOP)
  2216.  
  2217. realclean ::
  2218. });
  2219.  
  2220.     # realclean can get rather large.
  2221.     push @m, map "\t$_\n", $self->split_command('$(RM_F)', @to);
  2222.     push @m, "\n";
  2223.  
  2224.  
  2225.     # A target for each exe file.
  2226.     while (my($from,$to) = each %fromto) {
  2227.     last unless defined $from;
  2228.  
  2229.     push @m, sprintf <<'MAKE', $to, $from, $to, $from, $to, $to, $to;
  2230. %s : %s $(FIRST_MAKEFILE) $(INST_SCRIPT)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists
  2231.     $(NOECHO) $(RM_F) %s
  2232.     $(CP) %s %s
  2233.     $(FIXIN) %s
  2234.     -$(NOECHO) $(CHMOD) $(PERM_RWX) %s
  2235.  
  2236. MAKE
  2237.  
  2238.     }
  2239.  
  2240.     join "", @m;
  2241. }
  2242.  
  2243.  
  2244. =item linkext (o)
  2245.  
  2246. Defines the linkext target which in turn defines the LINKTYPE.
  2247.  
  2248. =cut
  2249.  
  2250. sub linkext {
  2251.     my($self, %attribs) = @_;
  2252.     # LINKTYPE => static or dynamic or ''
  2253.     my($linktype) = defined $attribs{LINKTYPE} ?
  2254.       $attribs{LINKTYPE} : '$(LINKTYPE)';
  2255.     "
  2256. linkext :: $linktype
  2257.     \$(NOECHO) \$(NOOP)
  2258. ";
  2259. }
  2260.  
  2261. =item lsdir
  2262.  
  2263. Takes as arguments a directory name and a regular expression. Returns
  2264. all entries in the directory that match the regular expression.
  2265.  
  2266. =cut
  2267.  
  2268. sub lsdir {
  2269.     my($self) = shift;
  2270.     my($dir, $regex) = @_;
  2271.     my(@ls);
  2272.     my $dh = new DirHandle;
  2273.     $dh->open($dir || ".") or return ();
  2274.     @ls = $dh->read;
  2275.     $dh->close;
  2276.     @ls = grep(/$regex/, @ls) if $regex;
  2277.     @ls;
  2278. }
  2279.  
  2280. =item macro (o)
  2281.  
  2282. Simple subroutine to insert the macros defined by the macro attribute
  2283. into the Makefile.
  2284.  
  2285. =cut
  2286.  
  2287. sub macro {
  2288.     my($self,%attribs) = @_;
  2289.     my(@m,$key,$val);
  2290.     while (($key,$val) = each %attribs){
  2291.     last unless defined $key;
  2292.     push @m, "$key = $val\n";
  2293.     }
  2294.     join "", @m;
  2295. }
  2296.  
  2297. =item makeaperl (o)
  2298.  
  2299. Called by staticmake. Defines how to write the Makefile to produce a
  2300. static new perl.
  2301.  
  2302. By default the Makefile produced includes all the static extensions in
  2303. the perl library. (Purified versions of library files, e.g.,
  2304. DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
  2305.  
  2306. =cut
  2307.  
  2308. sub makeaperl {
  2309.     my($self, %attribs) = @_;
  2310.     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
  2311.     @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
  2312.     my(@m);
  2313.     push @m, "
  2314. # --- MakeMaker makeaperl section ---
  2315. MAP_TARGET    = $target
  2316. FULLPERL      = $self->{FULLPERL}
  2317. ";
  2318.     return join '', @m if $self->{PARENT};
  2319.  
  2320.     my($dir) = join ":", @{$self->{DIR}};
  2321.  
  2322.     unless ($self->{MAKEAPERL}) {
  2323.     push @m, q{
  2324. $(MAP_TARGET) :: static $(MAKE_APERL_FILE)
  2325.     $(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@
  2326.  
  2327. $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE) pm_to_blib
  2328.     $(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
  2329.     $(NOECHO) $(PERLRUNINST) \
  2330.         Makefile.PL DIR=}, $dir, q{ \
  2331.         MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
  2332.         MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
  2333.  
  2334.     foreach (@ARGV){
  2335.         if( /\s/ ){
  2336.             s/=(.*)/='$1'/;
  2337.         }
  2338.         push @m, " \\\n\t\t$_";
  2339.     }
  2340. #    push @m, map( " \\\n\t\t$_", @ARGV );
  2341.     push @m, "\n";
  2342.  
  2343.     return join '', @m;
  2344.     }
  2345.  
  2346.  
  2347.  
  2348.     my($cccmd, $linkcmd, $lperl);
  2349.  
  2350.  
  2351.     $cccmd = $self->const_cccmd($libperl);
  2352.     $cccmd =~ s/^CCCMD\s*=\s*//;
  2353.     $cccmd =~ s/\$\(INC\)/ "-I$self->{PERL_INC}" /;
  2354.     $cccmd .= " $Config{cccdlflags}"
  2355.     if ($Config{useshrplib} eq 'true');
  2356.     $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
  2357.  
  2358.     # The front matter of the linkcommand...
  2359.     $linkcmd = join ' ', "\$(CC)",
  2360.         grep($_, @Config{qw(ldflags ccdlflags)});
  2361.     $linkcmd =~ s/\s+/ /g;
  2362.     $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
  2363.  
  2364.     # Which *.a files could we make use of...
  2365.     my %static;
  2366.     require File::Find;
  2367.     File::Find::find(sub {
  2368.     return unless m/\Q$self->{LIB_EXT}\E$/;
  2369.  
  2370.         # Skip perl's libraries.
  2371.         return if m/^libperl/ or m/^perl\Q$self->{LIB_EXT}\E$/;
  2372.  
  2373.     # Skip purified versions of libraries 
  2374.         # (e.g., DynaLoader_pure_p1_c0_032.a)
  2375.     return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
  2376.  
  2377.     if( exists $self->{INCLUDE_EXT} ){
  2378.         my $found = 0;
  2379.         my $incl;
  2380.         my $xx;
  2381.  
  2382.         ($xx = $File::Find::name) =~ s,.*?/auto/,,s;
  2383.         $xx =~ s,/?$_,,;
  2384.         $xx =~ s,/,::,g;
  2385.  
  2386.         # Throw away anything not explicitly marked for inclusion.
  2387.         # DynaLoader is implied.
  2388.         foreach $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
  2389.             if( $xx eq $incl ){
  2390.                 $found++;
  2391.                 last;
  2392.             }
  2393.         }
  2394.         return unless $found;
  2395.     }
  2396.     elsif( exists $self->{EXCLUDE_EXT} ){
  2397.         my $excl;
  2398.         my $xx;
  2399.  
  2400.         ($xx = $File::Find::name) =~ s,.*?/auto/,,s;
  2401.         $xx =~ s,/?$_,,;
  2402.         $xx =~ s,/,::,g;
  2403.  
  2404.         # Throw away anything explicitly marked for exclusion
  2405.         foreach $excl (@{$self->{EXCLUDE_EXT}}){
  2406.             return if( $xx eq $excl );
  2407.         }
  2408.     }
  2409.  
  2410.     # don't include the installed version of this extension. I
  2411.     # leave this line here, although it is not necessary anymore:
  2412.     # I patched minimod.PL instead, so that Miniperl.pm won't
  2413.     # enclude duplicates
  2414.  
  2415.     # Once the patch to minimod.PL is in the distribution, I can
  2416.     # drop it
  2417.     return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}\z:;
  2418.     use Cwd 'cwd';
  2419.     $static{cwd() . "/" . $_}++;
  2420.     }, grep( -d $_, @{$searchdirs || []}) );
  2421.  
  2422.     # We trust that what has been handed in as argument, will be buildable
  2423.     $static = [] unless $static;
  2424.     @static{@{$static}} = (1) x @{$static};
  2425.  
  2426.     $extra = [] unless $extra && ref $extra eq 'ARRAY';
  2427.     for (sort keys %static) {
  2428.     next unless /\Q$self->{LIB_EXT}\E\z/;
  2429.     $_ = dirname($_) . "/extralibs.ld";
  2430.     push @$extra, $_;
  2431.     }
  2432.  
  2433.     grep(s/^(.*)/"-I$1"/, @{$perlinc || []});
  2434.  
  2435.     $target ||= "perl";
  2436.     $tmp    ||= ".";
  2437.  
  2438. # MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
  2439. # regenerate the Makefiles, MAP_STATIC and the dependencies for
  2440. # extralibs.all are computed correctly
  2441.     push @m, "
  2442. MAP_LINKCMD   = $linkcmd
  2443. MAP_PERLINC   = @{$perlinc || []}
  2444. MAP_STATIC    = ",
  2445. join(" \\\n\t", reverse sort keys %static), "
  2446.  
  2447. MAP_PRELIBS   = $Config{perllibs} $Config{cryptlib}
  2448. ";
  2449.  
  2450.     if (defined $libperl) {
  2451.     ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
  2452.     }
  2453.     unless ($libperl && -f $lperl) { # Ilya's code...
  2454.     my $dir = $self->{PERL_SRC} || "/usr/lib";
  2455.     $dir = "$self->{PERL_ARCHLIB}/.." if $self->{UNINSTALLED_PERL};
  2456.     $libperl ||= "libperl$self->{LIB_EXT}";
  2457.     $libperl   = "$dir/$libperl";
  2458.     $lperl   ||= "libperl$self->{LIB_EXT}";
  2459.     $lperl     = "$dir/$lperl";
  2460.  
  2461.         if (! -f $libperl and ! -f $lperl) {
  2462.           # We did not find a static libperl. Maybe there is a shared one?
  2463.           if ($Is_SunOS) {
  2464.             $lperl  = $libperl = "$dir/$Config{libperl}";
  2465.             # SUNOS ld does not take the full path to a shared library
  2466.             $libperl = '' if $Is_SunOS4;
  2467.           }
  2468.         }
  2469.  
  2470.     print STDOUT "Warning: $libperl not found
  2471.     If you're going to build a static perl binary, make sure perl is installed
  2472.     otherwise ignore this warning\n"
  2473.         unless (-f $lperl || defined($self->{PERL_SRC}));
  2474.     }
  2475.  
  2476.     # SUNOS ld does not take the full path to a shared library
  2477.     my $llibperl = $libperl ? '$(MAP_LIBPERL)' : '-lperl';
  2478.  
  2479.     push @m, "
  2480. MAP_LIBPERL = $libperl
  2481. LLIBPERL    = $llibperl
  2482. ";
  2483.  
  2484.     push @m, '
  2485. $(INST_ARCHAUTODIR)/extralibs.all : $(INST_ARCHAUTODIR)$(DFSEP).exists '.join(" \\\n\t", @$extra).'
  2486.     $(NOECHO) $(RM_F)  $@
  2487.     $(NOECHO) $(TOUCH) $@
  2488. ';
  2489.  
  2490.     my $catfile;
  2491.     foreach $catfile (@$extra){
  2492.     push @m, "\tcat $catfile >> \$\@\n";
  2493.     }
  2494.  
  2495. push @m, "
  2496. \$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
  2497.     \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) \$(LDFROM) \$(MAP_STATIC) \$(LLIBPERL) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
  2498.     \$(NOECHO) \$(ECHO) 'To install the new \"\$(MAP_TARGET)\" binary, call'
  2499.     \$(NOECHO) \$(ECHO) '    \$(MAKE) \$(USEMAKEFILE) $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
  2500.     \$(NOECHO) \$(ECHO) 'To remove the intermediate files say'
  2501.     \$(NOECHO) \$(ECHO) '    \$(MAKE) \$(USEMAKEFILE) $makefilename map_clean'
  2502.  
  2503. $tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
  2504. ";
  2505.     push @m, "\t".$self->cd($tmp, qq[$cccmd "-I\$(PERL_INC)" perlmain.c])."\n";
  2506.  
  2507.     push @m, qq{
  2508. $tmp/perlmain.c: $makefilename}, q{
  2509.     $(NOECHO) $(ECHO) Writing $@
  2510.     $(NOECHO) $(PERL) $(MAP_PERLINC) "-MExtUtils::Miniperl" \\
  2511.         -e "writemain(grep s#.*/auto/##s, split(q| |, q|$(MAP_STATIC)|))" > $@t && $(MV) $@t $@
  2512.  
  2513. };
  2514.     push @m, "\t", q{$(NOECHO) $(PERL) $(INSTALLSCRIPT)/fixpmain
  2515. } if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
  2516.  
  2517.  
  2518.     push @m, q{
  2519. doc_inst_perl :
  2520.     $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
  2521.     -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
  2522.     -$(NOECHO) $(DOC_INSTALL) \
  2523.         "Perl binary" "$(MAP_TARGET)" \
  2524.         MAP_STATIC "$(MAP_STATIC)" \
  2525.         MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
  2526.         MAP_LIBPERL "$(MAP_LIBPERL)" \
  2527.         >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
  2528.  
  2529. };
  2530.  
  2531.     push @m, q{
  2532. inst_perl : pure_inst_perl doc_inst_perl
  2533.  
  2534. pure_inst_perl : $(MAP_TARGET)
  2535.     }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{
  2536.  
  2537. clean :: map_clean
  2538.  
  2539. map_clean :
  2540.     }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
  2541. };
  2542.  
  2543.     join '', @m;
  2544. }
  2545.  
  2546. =item makefile (o)
  2547.  
  2548. Defines how to rewrite the Makefile.
  2549.  
  2550. =cut
  2551.  
  2552. sub makefile {
  2553.     my($self) = shift;
  2554.     my $m;
  2555.     # We do not know what target was originally specified so we
  2556.     # must force a manual rerun to be sure. But as it should only
  2557.     # happen very rarely it is not a significant problem.
  2558.     $m = '
  2559. $(OBJECT) : $(FIRST_MAKEFILE)
  2560.  
  2561. ' if $self->{OBJECT};
  2562.  
  2563.     my $newer_than_target = $Is_VMS ? '$(MMS$SOURCE_LIST)' : '$?';
  2564.     my $mpl_args = join " ", map qq["$_"], @ARGV;
  2565.  
  2566.     $m .= sprintf <<'MAKE_FRAG', $newer_than_target, $mpl_args;
  2567. # We take a very conservative approach here, but it's worth it.
  2568. # We move Makefile to Makefile.old here to avoid gnu make looping.
  2569. $(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP)
  2570.     $(NOECHO) $(ECHO) "Makefile out-of-date with respect to %s"
  2571.     $(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..."
  2572.     -$(NOECHO) $(RM_F) $(MAKEFILE_OLD)
  2573.     -$(NOECHO) $(MV)   $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
  2574.     - $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL)
  2575.     $(PERLRUN) Makefile.PL %s
  2576.     $(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <=="
  2577.     $(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command.  <=="
  2578.     false
  2579.  
  2580. MAKE_FRAG
  2581.  
  2582.     return $m;
  2583. }
  2584.  
  2585.  
  2586. =item maybe_command
  2587.  
  2588. Returns true, if the argument is likely to be a command.
  2589.  
  2590. =cut
  2591.  
  2592. sub maybe_command {
  2593.     my($self,$file) = @_;
  2594.     return $file if -x $file && ! -d $file;
  2595.     return;
  2596. }
  2597.  
  2598.  
  2599. =item needs_linking (o)
  2600.  
  2601. Does this module need linking? Looks into subdirectory objects (see
  2602. also has_link_code())
  2603.  
  2604. =cut
  2605.  
  2606. sub needs_linking {
  2607.     my($self) = shift;
  2608.     my($child,$caller);
  2609.     $caller = (caller(0))[3];
  2610.     confess("needs_linking called too early") if 
  2611.       $caller =~ /^ExtUtils::MakeMaker::/;
  2612.     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
  2613.     if ($self->has_link_code or $self->{MAKEAPERL}){
  2614.     $self->{NEEDS_LINKING} = 1;
  2615.     return 1;
  2616.     }
  2617.     foreach $child (keys %{$self->{CHILDREN}}) {
  2618.     if ($self->{CHILDREN}->{$child}->needs_linking) {
  2619.         $self->{NEEDS_LINKING} = 1;
  2620.         return 1;
  2621.     }
  2622.     }
  2623.     return $self->{NEEDS_LINKING} = 0;
  2624. }
  2625.  
  2626.  
  2627. =item parse_abstract
  2628.  
  2629. parse a file and return what you think is the ABSTRACT
  2630.  
  2631. =cut
  2632.  
  2633. sub parse_abstract {
  2634.     my($self,$parsefile) = @_;
  2635.     my $result;
  2636.     local *FH;
  2637.     local $/ = "\n";
  2638.     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
  2639.     my $inpod = 0;
  2640.     my $package = $self->{DISTNAME};
  2641.     $package =~ s/-/::/g;
  2642.     while (<FH>) {
  2643.         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
  2644.         next if !$inpod;
  2645.         chop;
  2646.         next unless /^($package\s-\s)(.*)/;
  2647.         $result = $2;
  2648.         last;
  2649.     }
  2650.     close FH;
  2651.     return $result;
  2652. }
  2653.  
  2654. =item parse_version
  2655.  
  2656.     my $version = MM->parse_version($file);
  2657.  
  2658. Parse a $file and return what $VERSION is set to by the first assignment.
  2659. It will return the string "undef" if it can't figure out what $VERSION
  2660. is. $VERSION should be for all to see, so C<our $VERSION> or plain $VERSION
  2661. are okay, but C<my $VERSION> is not.
  2662.  
  2663. parse_version() will try to C<use version> before checking for C<$VERSION> so the following will work.
  2664.  
  2665.     $VERSION = qv(1.2.3);
  2666.  
  2667. =cut
  2668.  
  2669. sub parse_version {
  2670.     my($self,$parsefile) = @_;
  2671.     my $result;
  2672.     local *FH;
  2673.     local $/ = "\n";
  2674.     local $_;
  2675.     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
  2676.     my $inpod = 0;
  2677.     while (<FH>) {
  2678.         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
  2679.         next if $inpod || /^\s*#/;
  2680.         chop;
  2681.         next unless /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
  2682.         my $eval = qq{
  2683.             package ExtUtils::MakeMaker::_version;
  2684.             no strict;
  2685.             BEGIN { eval {
  2686.                 # Ensure any version() routine which might have leaked
  2687.                 # into this package has been deleted.  Interferes with
  2688.                 # version->import()
  2689.                 undef *version;
  2690.                 require version;
  2691.                 "version"->import;
  2692.             } }
  2693.  
  2694.             local $1$2;
  2695.             \$$2=undef;
  2696.             do {
  2697.                 $_
  2698.             }; \$$2
  2699.         };
  2700.         local $^W = 0;
  2701.         $result = eval($eval);
  2702.         warn "Could not eval '$eval' in $parsefile: $@" if $@;
  2703.         last;
  2704.     }
  2705.     close FH;
  2706.  
  2707.     $result = "undef" unless defined $result;
  2708.     return $result;
  2709. }
  2710.  
  2711.  
  2712. =item pasthru (o)
  2713.  
  2714. Defines the string that is passed to recursive make calls in
  2715. subdirectories.
  2716.  
  2717. =cut
  2718.  
  2719. sub pasthru {
  2720.     my($self) = shift;
  2721.     my(@m,$key);
  2722.  
  2723.     my(@pasthru);
  2724.     my($sep) = $Is_VMS ? ',' : '';
  2725.     $sep .= "\\\n\t";
  2726.  
  2727.     foreach $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
  2728.                      PREFIX INSTALL_BASE)
  2729.                  ) 
  2730.     {
  2731.         next unless defined $self->{$key};
  2732.     push @pasthru, "$key=\"\$($key)\"";
  2733.     }
  2734.  
  2735.     foreach $key (qw(DEFINE INC)) {
  2736.         next unless defined $self->{$key};
  2737.     push @pasthru, "PASTHRU_$key=\"\$(PASTHRU_$key)\"";
  2738.     }
  2739.  
  2740.     push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
  2741.     join "", @m;
  2742. }
  2743.  
  2744. =item perl_script
  2745.  
  2746. Takes one argument, a file name, and returns the file name, if the
  2747. argument is likely to be a perl script. On MM_Unix this is true for
  2748. any ordinary, readable file.
  2749.  
  2750. =cut
  2751.  
  2752. sub perl_script {
  2753.     my($self,$file) = @_;
  2754.     return $file if -r $file && -f _;
  2755.     return;
  2756. }
  2757.  
  2758. =item perldepend (o)
  2759.  
  2760. Defines the dependency from all *.h files that come with the perl
  2761. distribution.
  2762.  
  2763. =cut
  2764.  
  2765. sub perldepend {
  2766.     my($self) = shift;
  2767.     my(@m);
  2768.  
  2769.     my $make_config = $self->cd('$(PERL_SRC)', '$(MAKE) lib/Config.pm');
  2770.  
  2771.     push @m, sprintf <<'MAKE_FRAG', $make_config if $self->{PERL_SRC};
  2772. # Check for unpropogated config.sh changes. Should never happen.
  2773. # We do NOT just update config.h because that is not sufficient.
  2774. # An out of date config.h is not fatal but complains loudly!
  2775. $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
  2776.     -$(NOECHO) $(ECHO) "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
  2777.  
  2778. $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
  2779.     $(NOECHO) $(ECHO) "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
  2780.     %s
  2781. MAKE_FRAG
  2782.  
  2783.     return join "", @m unless $self->needs_linking;
  2784.  
  2785.     push @m, q{
  2786. PERL_HDRS = \
  2787.     $(PERL_INC)/EXTERN.h        \
  2788.     $(PERL_INC)/INTERN.h        \
  2789.     $(PERL_INC)/XSUB.h        \
  2790.     $(PERL_INC)/av.h        \
  2791.     $(PERL_INC)/cc_runtime.h    \
  2792.     $(PERL_INC)/config.h        \
  2793.     $(PERL_INC)/cop.h        \
  2794.     $(PERL_INC)/cv.h        \
  2795.     $(PERL_INC)/dosish.h        \
  2796.     $(PERL_INC)/embed.h        \
  2797.     $(PERL_INC)/embedvar.h        \
  2798.     $(PERL_INC)/fakethr.h        \
  2799.     $(PERL_INC)/form.h        \
  2800.     $(PERL_INC)/gv.h        \
  2801.     $(PERL_INC)/handy.h        \
  2802.     $(PERL_INC)/hv.h        \
  2803.     $(PERL_INC)/intrpvar.h        \
  2804.     $(PERL_INC)/iperlsys.h        \
  2805.     $(PERL_INC)/keywords.h        \
  2806.     $(PERL_INC)/mg.h        \
  2807.     $(PERL_INC)/nostdio.h        \
  2808.     $(PERL_INC)/op.h        \
  2809.     $(PERL_INC)/opcode.h        \
  2810.     $(PERL_INC)/patchlevel.h    \
  2811.     $(PERL_INC)/perl.h        \
  2812.     $(PERL_INC)/perlio.h        \
  2813.     $(PERL_INC)/perlsdio.h        \
  2814.     $(PERL_INC)/perlsfio.h        \
  2815.     $(PERL_INC)/perlvars.h        \
  2816.     $(PERL_INC)/perly.h        \
  2817.     $(PERL_INC)/pp.h        \
  2818.     $(PERL_INC)/pp_proto.h        \
  2819.     $(PERL_INC)/proto.h        \
  2820.     $(PERL_INC)/regcomp.h        \
  2821.     $(PERL_INC)/regexp.h        \
  2822.     $(PERL_INC)/regnodes.h        \
  2823.     $(PERL_INC)/scope.h        \
  2824.     $(PERL_INC)/sv.h        \
  2825.     $(PERL_INC)/thread.h        \
  2826.     $(PERL_INC)/unixish.h        \
  2827.     $(PERL_INC)/util.h
  2828.  
  2829. $(OBJECT) : $(PERL_HDRS)
  2830. } if $self->{OBJECT};
  2831.  
  2832.     push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
  2833.  
  2834.     join "\n", @m;
  2835. }
  2836.  
  2837.  
  2838. =item perm_rw (o)
  2839.  
  2840. Returns the attribute C<PERM_RW> or the string C<644>.
  2841. Used as the string that is passed
  2842. to the C<chmod> command to set the permissions for read/writeable files.
  2843. MakeMaker chooses C<644> because it has turned out in the past that
  2844. relying on the umask provokes hard-to-track bug reports.
  2845. When the return value is used by the perl function C<chmod>, it is
  2846. interpreted as an octal value.
  2847.  
  2848. =cut
  2849.  
  2850. sub perm_rw {
  2851.     return shift->{PERM_RW};
  2852. }
  2853.  
  2854. =item perm_rwx (o)
  2855.  
  2856. Returns the attribute C<PERM_RWX> or the string C<755>,
  2857. i.e. the string that is passed
  2858. to the C<chmod> command to set the permissions for executable files.
  2859. See also perl_rw.
  2860.  
  2861. =cut
  2862.  
  2863. sub perm_rwx {
  2864.     return shift->{PERM_RWX};
  2865. }
  2866.  
  2867. =item pm_to_blib
  2868.  
  2869. Defines target that copies all files in the hash PM to their
  2870. destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
  2871.  
  2872. =cut
  2873.  
  2874. sub pm_to_blib {
  2875.     my $self = shift;
  2876.     my($autodir) = $self->catdir('$(INST_LIB)','auto');
  2877.     my $r = q{
  2878. pm_to_blib : $(TO_INST_PM)
  2879. };
  2880.  
  2881.     my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
  2882. pm_to_blib({\@ARGV}, '$autodir', '\$(PM_FILTER)')
  2883. CODE
  2884.  
  2885.     my @cmds = $self->split_command($pm_to_blib, %{$self->{PM}});
  2886.  
  2887.     $r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds;
  2888.     $r .= qq{\t\$(NOECHO) \$(TOUCH) pm_to_blib\n};
  2889.  
  2890.     return $r;
  2891. }
  2892.  
  2893. =item post_constants (o)
  2894.  
  2895. Returns an empty string per default. Dedicated to overrides from
  2896. within Makefile.PL after all constants have been defined.
  2897.  
  2898. =cut
  2899.  
  2900. sub post_constants{
  2901.     "";
  2902. }
  2903.  
  2904. =item post_initialize (o)
  2905.  
  2906. Returns an empty string per default. Used in Makefile.PLs to add some
  2907. chunk of text to the Makefile after the object is initialized.
  2908.  
  2909. =cut
  2910.  
  2911. sub post_initialize {
  2912.     "";
  2913. }
  2914.  
  2915. =item postamble (o)
  2916.  
  2917. Returns an empty string. Can be used in Makefile.PLs to write some
  2918. text to the Makefile at the end.
  2919.  
  2920. =cut
  2921.  
  2922. sub postamble {
  2923.     "";
  2924. }
  2925.  
  2926. =item ppd
  2927.  
  2928. Defines target that creates a PPD (Perl Package Description) file
  2929. for a binary distribution.
  2930.  
  2931. =cut
  2932.  
  2933. sub ppd {
  2934.     my($self) = @_;
  2935.  
  2936.     my ($pack_ver) = join ",", (split (/\./, $self->{VERSION}), (0)x4)[0..3];
  2937.  
  2938.     my $abstract = $self->{ABSTRACT} || '';
  2939.     $abstract =~ s/\n/\\n/sg;
  2940.     $abstract =~ s/</</g;
  2941.     $abstract =~ s/>/>/g;
  2942.  
  2943.     my $author = $self->{AUTHOR} || '';
  2944.     $author =~ s/</</g;
  2945.     $author =~ s/>/>/g;
  2946.  
  2947.     my $ppd_xml = sprintf <<'PPD_HTML', $pack_ver, $abstract, $author;
  2948. <SOFTPKG NAME="$(DISTNAME)" VERSION="%s">
  2949.     <TITLE>$(DISTNAME)</TITLE>
  2950.     <ABSTRACT>%s</ABSTRACT>
  2951.     <AUTHOR>%s</AUTHOR>
  2952. PPD_HTML
  2953.  
  2954.     $ppd_xml .= "    <IMPLEMENTATION>\n";
  2955.     foreach my $prereq (sort keys %{$self->{PREREQ_PM}}) {
  2956.         my $pre_req = $prereq;
  2957.         $pre_req =~ s/::/-/g;
  2958.         my ($dep_ver) = join ",", (split (/\./, $self->{PREREQ_PM}{$prereq}), 
  2959.                                   (0) x 4) [0 .. 3];
  2960.         $ppd_xml .= sprintf <<'PPD_OUT', $pre_req, $dep_ver;
  2961.         <DEPENDENCY NAME="%s" VERSION="%s" />
  2962. PPD_OUT
  2963.  
  2964.     }
  2965.  
  2966.     my $archname = $Config{archname};
  2967.     if ($] >= 5.008) {
  2968.         # archname did not change from 5.6 to 5.8, but those versions may
  2969.         # not be not binary compatible so now we append the part of the
  2970.         # version that changes when binary compatibility may change
  2971.         $archname .= "-". substr($Config{version},0,3);
  2972.     }
  2973.     $ppd_xml .= sprintf <<'PPD_OUT', $archname;
  2974.         <OS NAME="$(OSNAME)" />
  2975.         <ARCHITECTURE NAME="%s" />
  2976. PPD_OUT
  2977.  
  2978.     if ($self->{PPM_INSTALL_SCRIPT}) {
  2979.         if ($self->{PPM_INSTALL_EXEC}) {
  2980.             $ppd_xml .= sprintf qq{        <INSTALL EXEC="%s">%s</INSTALL>\n},
  2981.                   $self->{PPM_INSTALL_EXEC}, $self->{PPM_INSTALL_SCRIPT};
  2982.         }
  2983.         else {
  2984.             $ppd_xml .= sprintf qq{        <INSTALL>%s</INSTALL>\n}, 
  2985.                   $self->{PPM_INSTALL_SCRIPT};
  2986.         }
  2987.     }
  2988.  
  2989.     my ($bin_location) = $self->{BINARY_LOCATION} || '';
  2990.     $bin_location =~ s/\\/\\\\/g;
  2991.  
  2992.     $ppd_xml .= sprintf <<'PPD_XML', $bin_location;
  2993.         <CODEBASE HREF="%s" />
  2994.     </IMPLEMENTATION>
  2995. </SOFTPKG>
  2996. PPD_XML
  2997.  
  2998.     my @ppd_cmds = $self->echo($ppd_xml, '$(DISTNAME).ppd');
  2999.  
  3000.     return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds;
  3001. # Creates a PPD (Perl Package Description) for a binary distribution.
  3002. ppd :
  3003.     %s
  3004. PPD_OUT
  3005.  
  3006. }
  3007.  
  3008. =item prefixify
  3009.  
  3010.   $MM->prefixify($var, $prefix, $new_prefix, $default);
  3011.  
  3012. Using either $MM->{uc $var} || $Config{lc $var}, it will attempt to
  3013. replace it's $prefix with a $new_prefix.  
  3014.  
  3015. Should the $prefix fail to match I<AND> a PREFIX was given as an
  3016. argument to WriteMakefile() it will set it to the $new_prefix +
  3017. $default.  This is for systems whose file layouts don't neatly fit into
  3018. our ideas of prefixes.
  3019.  
  3020. This is for heuristics which attempt to create directory structures
  3021. that mirror those of the installed perl.
  3022.  
  3023. For example:
  3024.  
  3025.     $MM->prefixify('installman1dir', '/usr', '/home/foo', 'man/man1');
  3026.  
  3027. this will attempt to remove '/usr' from the front of the
  3028. $MM->{INSTALLMAN1DIR} path (initializing it to $Config{installman1dir}
  3029. if necessary) and replace it with '/home/foo'.  If this fails it will
  3030. simply use '/home/foo/man/man1'.
  3031.  
  3032. =cut
  3033.  
  3034. sub prefixify {
  3035.     my($self,$var,$sprefix,$rprefix,$default) = @_;
  3036.  
  3037.     my $path = $self->{uc $var} || 
  3038.                $Config_Override{lc $var} || $Config{lc $var} || '';
  3039.  
  3040.     $rprefix .= '/' if $sprefix =~ m|/$|;
  3041.  
  3042.     print STDERR "  prefixify $var => $path\n" if $Verbose >= 2;
  3043.     print STDERR "    from $sprefix to $rprefix\n" if $Verbose >= 2;
  3044.  
  3045.     if( $path !~ s{^\Q$sprefix\E\b}{$rprefix}s && $self->{ARGS}{PREFIX} )
  3046.     {
  3047.  
  3048.         print STDERR "    cannot prefix, using default.\n" if $Verbose >= 2;
  3049.         print STDERR "    no default!\n" if !$default && $Verbose >= 2;
  3050.  
  3051.         $path = $self->catdir($rprefix, $default) if $default;
  3052.     }
  3053.  
  3054.     print "    now $path\n" if $Verbose >= 2;
  3055.     return $self->{uc $var} = $path;
  3056. }
  3057.  
  3058.  
  3059. =item processPL (o)
  3060.  
  3061. Defines targets to run *.PL files.
  3062.  
  3063. =cut
  3064.  
  3065. sub processPL {
  3066.     my $self = shift;
  3067.     my $pl_files = $self->{PL_FILES};
  3068.  
  3069.     return "" unless $pl_files;
  3070.  
  3071.     my $m = '';
  3072.     foreach my $plfile (sort keys %$pl_files) {
  3073.         my $list = ref($pl_files->{$plfile})
  3074.                      ?  $pl_files->{$plfile}
  3075.              : [$pl_files->{$plfile}];
  3076.  
  3077.     foreach my $target (@$list) {
  3078.             if( $Is_VMS ) {
  3079.                 $plfile = vmsify($self->eliminate_macros($plfile));
  3080.                 $target = vmsify($self->eliminate_macros($target));
  3081.             }
  3082.  
  3083.         # Normally a .PL file runs AFTER pm_to_blib so it can have
  3084.         # blib in its @INC and load the just built modules.  BUT if
  3085.         # the generated module is something in $(TO_INST_PM) which
  3086.         # pm_to_blib depends on then it can't depend on pm_to_blib
  3087.         # else we have a dependency loop.
  3088.         my $pm_dep;
  3089.         if( defined $self->{PM}{$target} ) {
  3090.         $pm_dep  = '';
  3091.         }
  3092.         else {
  3093.         $pm_dep  = 'pm_to_blib';
  3094.         }
  3095.  
  3096.             $m .= <<MAKE_FRAG;
  3097.  
  3098. all :: $target
  3099.     \$(NOECHO) \$(NOOP)
  3100.  
  3101. $target :: $plfile $pm_dep
  3102.     \$(PERLRUNINST) $plfile $target
  3103. MAKE_FRAG
  3104.  
  3105.     }
  3106.     }
  3107.  
  3108.     return $m;
  3109. }
  3110.  
  3111. =item quote_paren
  3112.  
  3113. Backslashes parentheses C<()> in command line arguments.
  3114. Doesn't handle recursive Makefile C<$(...)> constructs,
  3115. but handles simple ones.
  3116.  
  3117. =cut
  3118.  
  3119. sub quote_paren {
  3120.     my $arg = shift;
  3121.     $arg =~ s{\$\((.+?)\)}{\$\\\\($1\\\\)}g;    # protect $(...)
  3122.     $arg =~ s{(?<!\\)([()])}{\\$1}g;        # quote unprotected
  3123.     $arg =~ s{\$\\\\\((.+?)\\\\\)}{\$($1)}g;    # unprotect $(...)
  3124.     return $arg;
  3125. }
  3126.  
  3127. =item replace_manpage_separator
  3128.  
  3129.   my $man_name = $MM->replace_manpage_separator($file_path);
  3130.  
  3131. Takes the name of a package, which may be a nested package, in the
  3132. form 'Foo/Bar.pm' and replaces the slash with C<::> or something else
  3133. safe for a man page file name.  Returns the replacement.
  3134.  
  3135. =cut
  3136.  
  3137. sub replace_manpage_separator {
  3138.     my($self,$man) = @_;
  3139.  
  3140.     $man =~ s,/+,::,g;
  3141.     return $man;
  3142. }
  3143.  
  3144.  
  3145. =item cd
  3146.  
  3147. =cut
  3148.  
  3149. sub cd {
  3150.     my($self, $dir, @cmds) = @_;
  3151.  
  3152.     # No leading tab and no trailing newline makes for easier embedding
  3153.     my $make_frag = join "\n\t", map { "cd $dir && $_" } @cmds;
  3154.  
  3155.     return $make_frag;
  3156. }
  3157.  
  3158. =item oneliner
  3159.  
  3160. =cut
  3161.  
  3162. sub oneliner {
  3163.     my($self, $cmd, $switches) = @_;
  3164.     $switches = [] unless defined $switches;
  3165.  
  3166.     # Strip leading and trailing newlines
  3167.     $cmd =~ s{^\n+}{};
  3168.     $cmd =~ s{\n+$}{};
  3169.  
  3170.     my @cmds = split /\n/, $cmd;
  3171.     $cmd = join " \n\t  -e ", map $self->quote_literal($_), @cmds;
  3172.     $cmd = $self->escape_newlines($cmd);
  3173.  
  3174.     $switches = join ' ', @$switches;
  3175.  
  3176.     return qq{\$(ABSPERLRUN) $switches -e $cmd --};   
  3177. }
  3178.  
  3179.  
  3180. =item quote_literal
  3181.  
  3182. =cut
  3183.  
  3184. sub quote_literal {
  3185.     my($self, $text) = @_;
  3186.  
  3187.     # I think all we have to quote is single quotes and I think
  3188.     # this is a safe way to do it.
  3189.     $text =~ s{'}{'\\''}g;
  3190.  
  3191.     return "'$text'";
  3192. }
  3193.  
  3194.  
  3195. =item escape_newlines
  3196.  
  3197. =cut
  3198.  
  3199. sub escape_newlines {
  3200.     my($self, $text) = @_;
  3201.  
  3202.     $text =~ s{\n}{\\\n}g;
  3203.  
  3204.     return $text;
  3205. }
  3206.  
  3207.  
  3208. =item max_exec_len
  3209.  
  3210. Using POSIX::ARG_MAX.  Otherwise falling back to 4096.
  3211.  
  3212. =cut
  3213.  
  3214. sub max_exec_len {
  3215.     my $self = shift;
  3216.  
  3217.     if (!defined $self->{_MAX_EXEC_LEN}) {
  3218.         if (my $arg_max = eval { require POSIX;  &POSIX::ARG_MAX }) {
  3219.             $self->{_MAX_EXEC_LEN} = $arg_max;
  3220.         }
  3221.         else {      # POSIX minimum exec size
  3222.             $self->{_MAX_EXEC_LEN} = 4096;
  3223.         }
  3224.     }
  3225.  
  3226.     return $self->{_MAX_EXEC_LEN};
  3227. }
  3228.  
  3229.  
  3230. =item static (o)
  3231.  
  3232. Defines the static target.
  3233.  
  3234. =cut
  3235.  
  3236. sub static {
  3237. # --- Static Loading Sections ---
  3238.  
  3239.     my($self) = shift;
  3240.     '
  3241. ## $(INST_PM) has been moved to the all: target.
  3242. ## It remains here for awhile to allow for old usage: "make static"
  3243. static :: $(FIRST_MAKEFILE) $(INST_STATIC)
  3244.     $(NOECHO) $(NOOP)
  3245. ';
  3246. }
  3247.  
  3248. =item static_lib (o)
  3249.  
  3250. Defines how to produce the *.a (or equivalent) files.
  3251.  
  3252. =cut
  3253.  
  3254. sub static_lib {
  3255.     my($self) = @_;
  3256.     return '' unless $self->has_link_code;
  3257.  
  3258.     my(@m);
  3259.     push(@m, <<'END');
  3260.  
  3261. $(INST_STATIC) : $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
  3262.     $(RM_RF) $@
  3263. END
  3264.  
  3265.     # If this extension has its own library (eg SDBM_File)
  3266.     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
  3267.     push(@m, <<'MAKE_FRAG') if $self->{MYEXTLIB};
  3268.     $(CP) $(MYEXTLIB) $@
  3269. MAKE_FRAG
  3270.  
  3271.     my $ar; 
  3272.     if (exists $self->{FULL_AR} && -x $self->{FULL_AR}) {
  3273.         # Prefer the absolute pathed ar if available so that PATH
  3274.         # doesn't confuse us.  Perl itself is built with the full_ar.  
  3275.         $ar = 'FULL_AR';
  3276.     } else {
  3277.         $ar = 'AR';
  3278.     }
  3279.     push @m, sprintf <<'MAKE_FRAG', $ar;
  3280.     $(%s) $(AR_STATIC_ARGS) $@ $(OBJECT) && $(RANLIB) $@
  3281.     $(CHMOD) $(PERM_RWX) $@
  3282.     $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
  3283. MAKE_FRAG
  3284.  
  3285.     # Old mechanism - still available:
  3286.     push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
  3287.     $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
  3288. MAKE_FRAG
  3289.  
  3290.     join('', @m);
  3291. }
  3292.  
  3293. =item staticmake (o)
  3294.  
  3295. Calls makeaperl.
  3296.  
  3297. =cut
  3298.  
  3299. sub staticmake {
  3300.     my($self, %attribs) = @_;
  3301.     my(@static);
  3302.  
  3303.     my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
  3304.  
  3305.     # And as it's not yet built, we add the current extension
  3306.     # but only if it has some C code (or XS code, which implies C code)
  3307.     if (@{$self->{C}}) {
  3308.     @static = $self->catfile($self->{INST_ARCHLIB},
  3309.                  "auto",
  3310.                  $self->{FULLEXT},
  3311.                  "$self->{BASEEXT}$self->{LIB_EXT}"
  3312.                 );
  3313.     }
  3314.  
  3315.     # Either we determine now, which libraries we will produce in the
  3316.     # subdirectories or we do it at runtime of the make.
  3317.  
  3318.     # We could ask all subdir objects, but I cannot imagine, why it
  3319.     # would be necessary.
  3320.  
  3321.     # Instead we determine all libraries for the new perl at
  3322.     # runtime.
  3323.     my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
  3324.  
  3325.     $self->makeaperl(MAKE    => $self->{MAKEFILE},
  3326.              DIRS    => \@searchdirs,
  3327.              STAT    => \@static,
  3328.              INCL    => \@perlinc,
  3329.              TARGET    => $self->{MAP_TARGET},
  3330.              TMP    => "",
  3331.              LIBPERL    => $self->{LIBPERL_A}
  3332.             );
  3333. }
  3334.  
  3335. =item subdir_x (o)
  3336.  
  3337. Helper subroutine for subdirs
  3338.  
  3339. =cut
  3340.  
  3341. sub subdir_x {
  3342.     my($self, $subdir) = @_;
  3343.  
  3344.     my $subdir_cmd = $self->cd($subdir, 
  3345.       '$(MAKE) $(USEMAKEFILE) $(FIRST_MAKEFILE) all $(PASTHRU)'
  3346.     );
  3347.     return sprintf <<'EOT', $subdir_cmd;
  3348.  
  3349. subdirs ::
  3350.     $(NOECHO) %s
  3351. EOT
  3352.  
  3353. }
  3354.  
  3355. =item subdirs (o)
  3356.  
  3357. Defines targets to process subdirectories.
  3358.  
  3359. =cut
  3360.  
  3361. sub subdirs {
  3362. # --- Sub-directory Sections ---
  3363.     my($self) = shift;
  3364.     my(@m,$dir);
  3365.     # This method provides a mechanism to automatically deal with
  3366.     # subdirectories containing further Makefile.PL scripts.
  3367.     # It calls the subdir_x() method for each subdirectory.
  3368.     foreach $dir (@{$self->{DIR}}){
  3369.     push(@m, $self->subdir_x($dir));
  3370. ####    print "Including $dir subdirectory\n";
  3371.     }
  3372.     if (@m){
  3373.     unshift(@m, "
  3374. # The default clean, realclean and test targets in this Makefile
  3375. # have automatically been given entries for each subdir.
  3376.  
  3377. ");
  3378.     } else {
  3379.     push(@m, "\n# none")
  3380.     }
  3381.     join('',@m);
  3382. }
  3383.  
  3384. =item test (o)
  3385.  
  3386. Defines the test targets.
  3387.  
  3388. =cut
  3389.  
  3390. sub test {
  3391. # --- Test and Installation Sections ---
  3392.  
  3393.     my($self, %attribs) = @_;
  3394.     my $tests = $attribs{TESTS} || '';
  3395.     if (!$tests && -d 't') {
  3396.         $tests = $self->find_tests;
  3397.     }
  3398.     # note: 'test.pl' name is also hardcoded in init_dirscan()
  3399.     my(@m);
  3400.     push(@m,"
  3401. TEST_VERBOSE=0
  3402. TEST_TYPE=test_\$(LINKTYPE)
  3403. TEST_FILE = test.pl
  3404. TEST_FILES = $tests
  3405. TESTDB_SW = -d
  3406.  
  3407. testdb :: testdb_\$(LINKTYPE)
  3408.  
  3409. test :: \$(TEST_TYPE) subdirs-test
  3410.  
  3411. subdirs-test ::
  3412.     \$(NOECHO) \$(NOOP)
  3413.  
  3414. ");
  3415.  
  3416.     foreach my $dir (@{ $self->{DIR} }) {
  3417.         my $test = $self->cd($dir, '$(MAKE) test $(PASTHRU)');
  3418.  
  3419.         push @m, <<END
  3420. subdirs-test ::
  3421.     \$(NOECHO) $test
  3422.  
  3423. END
  3424.     }
  3425.  
  3426.     push(@m, "\t\$(NOECHO) \$(ECHO) 'No tests defined for \$(NAME) extension.'\n")
  3427.     unless $tests or -f "test.pl" or @{$self->{DIR}};
  3428.     push(@m, "\n");
  3429.  
  3430.     push(@m, "test_dynamic :: pure_all\n");
  3431.     push(@m, $self->test_via_harness('$(FULLPERLRUN)', '$(TEST_FILES)')) 
  3432.       if $tests;
  3433.     push(@m, $self->test_via_script('$(FULLPERLRUN)', '$(TEST_FILE)')) 
  3434.       if -f "test.pl";
  3435.     push(@m, "\n");
  3436.  
  3437.     push(@m, "testdb_dynamic :: pure_all\n");
  3438.     push(@m, $self->test_via_script('$(FULLPERLRUN) $(TESTDB_SW)', 
  3439.                                     '$(TEST_FILE)'));
  3440.     push(@m, "\n");
  3441.  
  3442.     # Occasionally we may face this degenerate target:
  3443.     push @m, "test_ : test_dynamic\n\n";
  3444.  
  3445.     if ($self->needs_linking()) {
  3446.     push(@m, "test_static :: pure_all \$(MAP_TARGET)\n");
  3447.     push(@m, $self->test_via_harness('./$(MAP_TARGET)', '$(TEST_FILES)')) if $tests;
  3448.     push(@m, $self->test_via_script('./$(MAP_TARGET)', '$(TEST_FILE)')) if -f "test.pl";
  3449.     push(@m, "\n");
  3450.     push(@m, "testdb_static :: pure_all \$(MAP_TARGET)\n");
  3451.     push(@m, $self->test_via_script('./$(MAP_TARGET) $(TESTDB_SW)', '$(TEST_FILE)'));
  3452.     push(@m, "\n");
  3453.     } else {
  3454.     push @m, "test_static :: test_dynamic\n";
  3455.     push @m, "testdb_static :: testdb_dynamic\n";
  3456.     }
  3457.     join("", @m);
  3458. }
  3459.  
  3460. =item test_via_harness (override)
  3461.  
  3462. For some reason which I forget, Unix machines like to have
  3463. PERL_DL_NONLAZY set for tests.
  3464.  
  3465. =cut
  3466.  
  3467. sub test_via_harness {
  3468.     my($self, $perl, $tests) = @_;
  3469.     return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=1 $perl", $tests);
  3470. }
  3471.  
  3472. =item test_via_script (override)
  3473.  
  3474. Again, the PERL_DL_NONLAZY thing.
  3475.  
  3476. =cut
  3477.  
  3478. sub test_via_script {
  3479.     my($self, $perl, $script) = @_;
  3480.     return $self->SUPER::test_via_script("PERL_DL_NONLAZY=1 $perl", $script);
  3481. }
  3482.  
  3483.  
  3484. =item tools_other (o)
  3485.  
  3486.     my $make_frag = $MM->tools_other;
  3487.  
  3488. Returns a make fragment containing definitions for the macros init_others() 
  3489. initializes.
  3490.  
  3491. =cut
  3492.  
  3493. sub tools_other {
  3494.     my($self) = shift;
  3495.     my @m;
  3496.  
  3497.     # We set PM_FILTER as late as possible so it can see all the earlier
  3498.     # on macro-order sensitive makes such as nmake.
  3499.     for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH 
  3500.                       UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP 
  3501.                       ECHO ECHO_N
  3502.                       UNINST VERBINST
  3503.                       MOD_INSTALL DOC_INSTALL UNINSTALL
  3504.                       WARN_IF_OLD_PACKLIST
  3505.               MACROSTART MACROEND
  3506.                       USEMAKEFILE
  3507.                       PM_FILTER
  3508.                       FIXIN
  3509.                     } ) 
  3510.     {
  3511.         next unless defined $self->{$tool};
  3512.         push @m, "$tool = $self->{$tool}\n";
  3513.     }
  3514.  
  3515.     return join "", @m;
  3516. }
  3517.  
  3518. =item tool_xsubpp (o)
  3519.  
  3520. Determines typemaps, xsubpp version, prototype behaviour.
  3521.  
  3522. =cut
  3523.  
  3524. sub tool_xsubpp {
  3525.     my($self) = shift;
  3526.     return "" unless $self->needs_linking;
  3527.  
  3528.     my $xsdir;
  3529.     my @xsubpp_dirs = @INC;
  3530.  
  3531.     # Make sure we pick up the new xsubpp if we're building perl.
  3532.     unshift @xsubpp_dirs, $self->{PERL_LIB} if $self->{PERL_CORE};
  3533.  
  3534.     foreach my $dir (@xsubpp_dirs) {
  3535.         $xsdir = $self->catdir($dir, 'ExtUtils');
  3536.         if( -r $self->catfile($xsdir, "xsubpp") ) {
  3537.             last;
  3538.         }
  3539.     }
  3540.  
  3541.     my $tmdir   = File::Spec->catdir($self->{PERL_LIB},"ExtUtils");
  3542.     my(@tmdeps) = $self->catfile($tmdir,'typemap');
  3543.     if( $self->{TYPEMAPS} ){
  3544.     my $typemap;
  3545.     foreach $typemap (@{$self->{TYPEMAPS}}){
  3546.         if( ! -f  $typemap ){
  3547.             warn "Typemap $typemap not found.\n";
  3548.         }
  3549.         else{
  3550.             push(@tmdeps,  $typemap);
  3551.         }
  3552.     }
  3553.     }
  3554.     push(@tmdeps, "typemap") if -f "typemap";
  3555.     my(@tmargs) = map("-typemap $_", @tmdeps);
  3556.     if( exists $self->{XSOPT} ){
  3557.      unshift( @tmargs, $self->{XSOPT} );
  3558.     }
  3559.  
  3560.     if ($Is_VMS                          &&
  3561.         $Config{'ldflags'}               && 
  3562.         $Config{'ldflags'} =~ m!/Debug!i &&
  3563.         (!exists($self->{XSOPT}) || $self->{XSOPT} !~ /linenumbers/)
  3564.        ) 
  3565.     {
  3566.         unshift(@tmargs,'-nolinenumbers');
  3567.     }
  3568.  
  3569.  
  3570.     $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
  3571.  
  3572.     return qq{
  3573. XSUBPPDIR = $xsdir
  3574. XSUBPP = \$(XSUBPPDIR)\$(DFSEP)xsubpp
  3575. XSUBPPRUN = \$(PERLRUN) \$(XSUBPP)
  3576. XSPROTOARG = $self->{XSPROTOARG}
  3577. XSUBPPDEPS = @tmdeps \$(XSUBPP)
  3578. XSUBPPARGS = @tmargs
  3579. XSUBPP_EXTRA_ARGS = 
  3580. };
  3581. };
  3582.  
  3583.  
  3584. =item all_target
  3585.  
  3586. Build man pages, too
  3587.  
  3588. =cut
  3589.  
  3590. sub all_target {
  3591.     my $self = shift;
  3592.  
  3593.     return <<'MAKE_EXT';
  3594. all :: pure_all manifypods
  3595.     $(NOECHO) $(NOOP)
  3596. MAKE_EXT
  3597. }
  3598.  
  3599. =item top_targets (o)
  3600.  
  3601. Defines the targets all, subdirs, config, and O_FILES
  3602.  
  3603. =cut
  3604.  
  3605. sub top_targets {
  3606. # --- Target Sections ---
  3607.  
  3608.     my($self) = shift;
  3609.     my(@m);
  3610.  
  3611.     push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'};
  3612.  
  3613.     push @m, '
  3614. pure_all :: config pm_to_blib subdirs linkext
  3615.     $(NOECHO) $(NOOP)
  3616.  
  3617. subdirs :: $(MYEXTLIB)
  3618.     $(NOECHO) $(NOOP)
  3619.  
  3620. config :: $(FIRST_MAKEFILE) blibdirs
  3621.     $(NOECHO) $(NOOP)
  3622. ';
  3623.  
  3624.     push @m, '
  3625. $(O_FILES): $(H_FILES)
  3626. ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
  3627.  
  3628.     push @m, q{
  3629. help :
  3630.     perldoc ExtUtils::MakeMaker
  3631. };
  3632.  
  3633.     join('',@m);
  3634. }
  3635.  
  3636. =item writedoc
  3637.  
  3638. Obsolete, deprecated method. Not used since Version 5.21.
  3639.  
  3640. =cut
  3641.  
  3642. sub writedoc {
  3643. # --- perllocal.pod section ---
  3644.     my($self,$what,$name,@attribs)=@_;
  3645.     my $time = localtime;
  3646.     print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
  3647.     print join "\n\n=item *\n\n", map("C<$_>",@attribs);
  3648.     print "\n\n=back\n\n";
  3649. }
  3650.  
  3651. =item xs_c (o)
  3652.  
  3653. Defines the suffix rules to compile XS files to C.
  3654.  
  3655. =cut
  3656.  
  3657. sub xs_c {
  3658.     my($self) = shift;
  3659.     return '' unless $self->needs_linking();
  3660.     '
  3661. .xs.c:
  3662.     $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c
  3663. ';
  3664. }
  3665.  
  3666. =item xs_cpp (o)
  3667.  
  3668. Defines the suffix rules to compile XS files to C++.
  3669.  
  3670. =cut
  3671.  
  3672. sub xs_cpp {
  3673.     my($self) = shift;
  3674.     return '' unless $self->needs_linking();
  3675.     '
  3676. .xs.cpp:
  3677.     $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.cpp
  3678. ';
  3679. }
  3680.  
  3681. =item xs_o (o)
  3682.  
  3683. Defines suffix rules to go from XS to object files directly. This is
  3684. only intended for broken make implementations.
  3685.  
  3686. =cut
  3687.  
  3688. sub xs_o {    # many makes are too dumb to use xs_c then c_o
  3689.     my($self) = shift;
  3690.     return '' unless $self->needs_linking();
  3691.     '
  3692. .xs$(OBJ_EXT):
  3693.     $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c
  3694.     $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c
  3695. ';
  3696. }
  3697.  
  3698.  
  3699. 1;
  3700.  
  3701. =back
  3702.  
  3703. =head1 SEE ALSO
  3704.  
  3705. L<ExtUtils::MakeMaker>
  3706.  
  3707. =cut
  3708.  
  3709. __END__
  3710.